git - 无法将提交两次推送到我的遥控器
问题描述
我正在尝试将修改后的提交从一个存储库推送到另一个存储库(在另一台机器上),并且无法理解为什么它第二次无法正常工作。
我的会话(已编辑,但仍然相关):
[/c/git/repo] (mybranch)
[user] $ git commit -a --amend
[mybranch ad1804290] Add filtering
Date: Thu Jun 21 09:50:43 2018 -0400
26 files changed, 2302 insertions(+), 2006 deletions(-)
[user] $ git push centos7vm mybranch
Counting objects: 157, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (135/135), done.
Writing objects: 100% (157/157), 59.76 KiB | 3.51 MiB/s, done.
Total 157 (delta 121), reused 34 (delta 15)
To ssh://mymachine/home/user/git/repo
* [new branch] mybranch -> mybranch
有效,对吧?让我们进行一些更改,然后再试一次:
[/c/git/repo] (mybranch)
[user] $ git commit -a --amend
[mybranch 26c680cbf] Add filtering
Date: Thu Jun 21 09:55:43 2018 -0400
26 files changed, 2302 insertions(+), 2006 deletions(-)
[/c/git/repo] (mybranch)
[user] $ git push centos7vm mybranch
To ssh://mymachine/home/user/git/repo
! [rejected] mybranch -> mybranch (non-fast-forward)
error: failed to push some refs to 'ssh://user@mymachine/home/user/git/repo'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
失败……但是,为什么?我什至没有检查远程分支上的任何更改。我当前的分支怎么可能在遥控器后面?这对我来说毫无意义。
我的远程设置:
[user] $ git remote show centos7vm
* remote centos7vm
Fetch URL: ssh://user@mymachine/home/user/git/repo
Push URL: ssh://user@mymachine/home/user/git/repo
HEAD branch: development
Remote branches:
Local refs configured for 'git push':
development pushes to development (fast-forwardable)
mybranch pushes to mybranch (local out of date)
解决方案
如果您仔细查看您的命令,您会发现--amend
实际上创建了一个新的提交。
第一次尝试:
[user] $ git commit -a --amend
[mybranch ad1804290] Add filtering
第二次尝试:
[user] $ git commit -a --amend
[mybranch 26c680cbf] Add filtering
(ad1804290
对26c680cbf
)
在推送之后更改提交很少是一个好主意。我会保持原样。如果您需要更改,只需创建一个新的提交。
由于您自己工作push --force
可能在这里没问题,但使用-f
是一个非常糟糕的习惯。
如果您不修改推送的提交,那就更好了。
推荐阅读
- ios - 无法在横向模式下强制旋转方向
- linux - 使用 Nginx 在 Ubuntu 上托管多个 .net 核心应用程序
- ajax - 未定义的偏移量:0 在 HandleExceptions->handleError
- vue.js - 深入了解 v-data-table 中的对象超属性
- powershell - Powershell 终止执行
- python - 没有使用带有 Python 的 json.dumps 获得所需的值
- c - 涉及将文件读入 C 中的 char 数组的警告
- javascript - 如何在 JavaScript 中从数组创建嵌套的子对象?
- java - SpringXD Kryo-shaded-3.0.3.jar 和 NoClassDefFoundError 和 ClassNotFoundException 和 Enum
- android - 如何在 Room Db 上使用挂起功能?