我正在寻找一个 git 命令来帮助我处理我的功能分支,当它们准备好进入 Master 时。这个 git 命令会将我在分支上的所有更改压缩到 master 之上的单个提交中。我今天这样做:
git rebase origin/master
git rebase -i HEAD~4
其中 4 是压缩的提交数。但是,这需要我知道我有多少次提交。我今天通过运行来做到这一点:
git log HEAD...origin/master
然后计算提交数。
我觉得好像应该有更好的方法来做到这一点。或者其他人也是这样做的?
最佳答案
您所要做的就是:
git checkout feature_branch
git rebase master
git checkout master
git merge --squash feature_branch
作为docs对于 git merge --squash
说:
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a merge commit. This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).
之后,您可以git commit
您已经暂存的更改。
关于Git rebase (Merge Squash) 我的功能分支到另一个分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9622131/