要在github中挤压多个提交吗
我想用提交消息“first”和“second”挤压两个最新的提交。首先我拉主,然后我使用命令要在github中挤压多个提交吗,github,Github,我想用提交消息“first”和“second”挤压两个最新的提交。首先我拉主,然后我使用命令 git rebase -i HEAD~2 master 它向我展示了编辑器中的两个提交,如下所示: pick first pick second 然后我将此编辑器更改为: pick first squash second 保存更改后,我收到以下消息: Successfully rebased and updated refs/heads/master. 它确实改变了远程主机中的任何内容。为了应用
git rebase -i HEAD~2 master
它向我展示了编辑器中的两个提交,如下所示:
pick first
pick second
然后我将此编辑器更改为:
pick first
squash second
保存更改后,我收到以下消息:
Successfully rebased and updated refs/heads/master.
它确实改变了远程主机中的任何内容。为了应用这些更改,我使用了git push
命令,并得到以下错误:
To https://github.com/aneelatest/GITtest.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/test/GITtest.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
然后我再次运行git pull
命令,它合并原始主机并使用此提交消息进行另一次提交:
Merge branch 'master' of https://github.com/aneelatest/GITtest
之后,当我运行gitpush时,它会将两个提交压缩为一个,并显示消息“first”。
问题是,在remote master中,我现在有四个提交:
first
second
Merge branch 'master' of https://github.com/test/GITtest
first
其中,我只需要一个提交,它是带有提交消息“first”的压缩提交。
任何我犯错误的想法???
git-rebase
重写历史,因为提交被修改了。当所述提交没有被推送到远程存储库时,这不是问题,但是在这里,远程存储库之前是用您重写的提交推送的,所以它拒绝了推送
当您从github中提取时,它合并了这两个历史记录,并应用了挤压提交,因此造成了混乱
结论:当您想要重写已经推送的提交时,有两个选项:
- 不要这样做
- 做一个git push--force,它也会在遥控器上重写历史,并告诉人们你已经重写了历史,这样他们在下一次拉动时会看到奇怪的事情