想要在github中压缩多个提交 [英] want to squash multiple commits in github
问题描述
我想用提交消息第一和第二压缩两个最新的提交。首先我拉大师,然后我使用命令
$ g $ reb $ -i HEAD〜2 master
$ / code>
它向我展示了这样一个编辑器中的提交:
选择第一个
选择第二个
然后我将此编辑器更改为:
选取第一个
压缩第二个
保存更改后,我收到了以下消息:
成功更新并更新了参考文献/主。
它确实改变了远程主人的任何内容。要应用这些更改,我使用 git push
命令并得到以下错误:
到https://github.com/aneelatest/GITtest.git
! [被拒绝] master - > master(非快速转发)
错误:未能将某些文件推送到'https://github.com/test/GITtest.git'
提示:由于当前提示分支在
提示后面:它的远程对手。合并远程更改(例如'git pull')
提示:再次按下之前。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。
然后我再次运行 git pull
命令它会合并原始主机并使用此提交消息进行另一次提交:
合并https:// github的分支'master'。 com / aneelatest / GITtest
在此之后,我运行git push,它将两个提交压缩成一个消息第一。
问题是,在远程主服务器上,我现在有四个提交:
第一个
第二个
合并https://github.com/test/GITtest分支'master'
首先
在哪里我只需要一个提交,它是一个提交消息第一个压缩的提交。
任何想法,我在做错误??
git rebase
重写历史记录,因为提交已被修改。当所述提交没有被推送到远程仓库时,这不是问题,但是这里的远程以前是用你重写的提交按下的,所以它拒绝了推送。
当你从github中提取时,它将两个历史合并在一起,并且应用了你的压扁提交,所以这个混乱。结束语:当你想重写已经提交的提交时推送,你有两个选择:
$ ul
git push --force
,它会在远程地址上重写历史记录,并告诉人们你已经重写了历史记录,所以他们会在下一次拉动时看到奇怪的事情。
I want to squash two latest commits with commit messages "first" and "second". First I pull master then I use the command
git rebase -i HEAD~2 master
It shows me both commits in an editor like this:
pick first
pick second
Then I change this editor as:
pick first
squash second
After saving the changes I got this message:
Successfully rebased and updated refs/heads/master.
It did change anything in remote master. To apply these changes I use the git push
command and got the following error:
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.
Then I again run the git pull
command and it merge origin master and make another commit with this commit message:
Merge branch 'master' of https://github.com/aneelatest/GITtest
After this when I run git push, it squash the two commits into one with message "first". The problem is that in remote master, I have now four commits:
first
second
Merge branch 'master' of https://github.com/test/GITtest
first
Where I want only one commit which is the squashed one with commit message"first". Any ideas where I am doing mistake??
git rebase
rewrites history, because the commits were modified. It's not a problem when the said commits haven't been pushed to a remote repository, but here the remote was previously pushed with the commits you rewrote, so it rejected the push.
When you pulled from github, it merged both histories, and applied your squash commit, hence the mess.
Conclusion: when you want to rewrite commits that has already been pushed, you have two options:
- don't do it
- do a
git push --force
, which will rewrite history also on the remote, and tell people that you have rewrote history, so they'll see strange things on their next pull.
这篇关于想要在github中压缩多个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!