推送到远程迫使我撤消本地硬重置
Pushing to remote forcing me to undo my local hard reset
我正在使用 git CommandLine 来学习,以及 SourceTree 来可视化各种命令的效果.
我从头开始,进行了 4 次更改,因此进行了 4 次提交,并向我的 origin master 推送了 4 次:
commit a
commit b
commit c
commit d
然后,在创建这些提交之前,我发出命令 git reset --hard <initialID>
将我带到我刚开始的地方。
我可以在 SourceTree 上看到我已成功删除所有提交并将所有内容重置为初始状态。
当然,我从 SourceTree 收到通知,我现在落后于远程原始主机 4 个提交,这是真的!
现在,我尝试推送我的当前状态,以便我的遥控器也更新;即重新开始,就像我现在的本地状态一样。
然而,这被拒绝了,所以我想知道是否有一个特殊的命令来强制推送并删除我所有的提交并将所有内容硬重置回我的远程[=32]上的初始状态=]?
p.s. 显然,当我听取SourceTree的建议再次拉取时,我又回到了我最近的4次提交情况;这意味着这取消了我的硬重置,所以我不应该拉,而是尝试将我当前的新状态推到遥控器上,这样我的硬重置也会反映在遥控器上,但我该怎么做?
强制 (-f) 推送。
注意:该命令是危险的,它会将您远程主机的提交历史替换为本地主机的提交历史。
$ git push -f origin master
Git 非常善于在大多数情况下为您提供有用的错误消息,我只是在本地复制了您的示例,并向我展示了
! [rejected]
error: failed to push some refs to {myRepo}
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.
'git push --help' 然后调出 'git push' 的文档(包含很多有用的信息!),包括关于 --force 标志的文档
-f
--force
Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected.
This flag disables these checks, and can cause the remote repository to lose commits; use it with care.
Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.*.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch). See the < refspec>... section above for details.
我正在使用 git CommandLine 来学习,以及 SourceTree 来可视化各种命令的效果.
我从头开始,进行了 4 次更改,因此进行了 4 次提交,并向我的 origin master 推送了 4 次:
commit a
commit b
commit c
commit d
然后,在创建这些提交之前,我发出命令 git reset --hard <initialID>
将我带到我刚开始的地方。
我可以在 SourceTree 上看到我已成功删除所有提交并将所有内容重置为初始状态。
当然,我从 SourceTree 收到通知,我现在落后于远程原始主机 4 个提交,这是真的!
现在,我尝试推送我的当前状态,以便我的遥控器也更新;即重新开始,就像我现在的本地状态一样。
然而,这被拒绝了,所以我想知道是否有一个特殊的命令来强制推送并删除我所有的提交并将所有内容硬重置回我的远程[=32]上的初始状态=]?
p.s. 显然,当我听取SourceTree的建议再次拉取时,我又回到了我最近的4次提交情况;这意味着这取消了我的硬重置,所以我不应该拉,而是尝试将我当前的新状态推到遥控器上,这样我的硬重置也会反映在遥控器上,但我该怎么做?
强制 (-f) 推送。
注意:该命令是危险的,它会将您远程主机的提交历史替换为本地主机的提交历史。
$ git push -f origin master
Git 非常善于在大多数情况下为您提供有用的错误消息,我只是在本地复制了您的示例,并向我展示了
! [rejected]
error: failed to push some refs to {myRepo}
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.
'git push --help' 然后调出 'git push' 的文档(包含很多有用的信息!),包括关于 --force 标志的文档
-f
--force
Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected.This flag disables these checks, and can cause the remote repository to lose commits; use it with care.
Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.*.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch). See the < refspec>... section above for details.