【发布时间】:2017-05-09 01:51:13
【问题描述】:
我有一个分支 A 和一个分支 B。分支 B 比 A 提前三个提交。
我可以使用git diff 列出A 和B 之间更改的文件。
但我的问题是:当我在 A 上时,如何检查 A 和 B 之间所有已更改的文件,然后将它们作为一个提交全部提交到 A 中?
【问题讨论】:
标签: git merge commit git-branch git-checkout
我有一个分支 A 和一个分支 B。分支 B 比 A 提前三个提交。
我可以使用git diff 列出A 和B 之间更改的文件。
但我的问题是:当我在 A 上时,如何检查 A 和 B 之间所有已更改的文件,然后将它们作为一个提交全部提交到 A 中?
【问题讨论】:
标签: git merge commit git-branch git-checkout
如果B 严格领先于A(而不是落后于它),那么您可以简单地运行“merge --squash”:
git merge --squash B
git commit
【讨论】:
只需将B 分支拉入A,然后将最后三个提交合并为一个。
$ git checkout A
$ git pull origin B
$ git log
# Now top 3 commits are B's commit
# now back to 3 commits but exists all changes of that 3 commits (soft reset)
$ git log
# copy the last commit-hash of A (before pulled)
$ git reset --soft <commit-hash>
# now do one commit with all changes
$ git add .
$ git commit -m 'add last 3 commits of B as one in A'
$ git push origin HEAD # push the changes to remote
【讨论】:
将提交重新定位到 A 上,然后使用
将它们一起压缩为一个提交git rebase -i HEAD~3
【讨论】:
通过 rebase 从 B 获取提交
git rebase B
现在将三个提交压缩为一个
git rebase -i HEAD~3
【讨论】: