有没有办法压缩并将master合并到同一个分支中?有效地获取所有挂起的提交并将它们置于1次提交中?
我最初的想法是一个脚本,它采取my-branch
并做一个git checkout master && git pull && git checkout my-branch-squashed
然后 git merge --squash my-branch
(处理任何合并冲突),然后最终删除my-branch
并重命名my-branch-squash
为my-branch
这似乎非常圆,可能不好,所以我试图看看是否还有其他方法.我试图解决的意图是,当我在github上放置分支并将它们"压缩并合并"到master中时,本地机器上存在的分支与合并到master中的分支不匹配,因此在使用git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d;
它时没有正确删除已合并为master的分支.我想要的是一种自动删除已合并为master的旧分支的方法
您可以使用git rebase
并修复要合并的提交:
$ git rebase -i HEAD~5 pick c2e2c87 commit 1 f 689d474 commit 2 f aa9d9b4 commit 3 f 888a009 commit 4 f d396e75 commit 5 # Rebase 2f7f53e..d396e75 onto 2f7f53e (5 commands) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out
您可以使用git rebase -i --root
以便从第一次提交中进行rebase.