本文介绍了将推送的提交压缩为一次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试将两个推送的提交压缩为一个提交.在四处搜寻之后,我发现可以通过重置三个提交来有效地压缩提交.我这样做了,但是尝试再次提交更改会导致出现一条消息,指出我正在提交给已分离的头.
I'm currently trying to squash two pushed commits into one single commit. After searching around on, I've found that commits can effectively be squashed by resetting three commits ago. I did this, but attempting to commit the changes again results in a message stating that I'm committing to a detatched head.
我从这里做什么?
推荐答案
重写与他人共享的提交通常是一个非常糟糕的主意,但是如果您知道陷阱并且可以接受后果,那么...
It's generally a very bad idea to rewrite commits that have been shared with others, but if you're aware of the pitfalls and are OK with the consequences, then...
-
git rebase -i< sha_of_commit_older_than_the_oldest_you_want_to_squash>
- 如有必要,对交互式变基配方中的行进行重新排序,以使要压缩的所有提交彼此相邻 您要压在一起的提交中的
- ,用
squash
标记第二个及以后的提交 - 保存,退出并等待变基完成
-
git push -f
- 准备好用干草叉和火把保护自己免受暴民的侵害
git rebase -i <sha_of_commit_older_than_the_oldest_you_want_to_squash>
- if necessary, reorder the lines in the interactive rebase recipe to put all of the commits you want to squash together next to each other
- of the commits you want to squash together, mark the second and later commits with
squash
- save, exit, and wait for rebase to finish
git push -f
- get ready to defend yourself against a mob with pitchforks and torches
这篇关于将推送的提交压缩为一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!