如何在两个提交之间检出所有更改的文件

3

我有一个分支A和一个分支B。分支B比分支A多三个提交。

我可以使用git diff列出在A和B之间更改的文件。

但我的问题是:当我在A上时,如何检出所有这些在A和B之间更改的文件,然后将它们作为一次提交全部提交到A中?

4个回答

1
如果B严格在A之前(而不是之后),则可以简单地运行"merge --squash":
git merge --squash B
git commit

1
谢谢@max630,我只需要在你的答案中将A替换为B,因为我正在A上并且想要从B检出/合并文件。 - EizEddin
当然,应该是B。我的错误。我会编辑答案。 - max630

1
只需将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

0
将提交记录变基到 A 上,然后将它们压缩成一个提交记录。
git rebase -i HEAD~3

0
从 B 开始通过变基获取提交
git 变基 B
现在将三个提交压缩成一个
git 变基 -i HEAD~3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接