【问题标题】:git - How to checkout all changed files between two commitsgit - 如何在两次提交之间签出所有更改的文件
【发布时间】: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


    【解决方案1】:

    如果B 严格领先于A(而不是落后于它),那么您可以简单地运行“merge --squash”:

    git merge --squash B
    git commit
    

    【讨论】:

    • 谢谢@max630,我只需要在你的答案中用 B 替换 A,因为我在 A 上并想从 B 签出/合并文件
    • 当然,应该是 B。我的错。我会编辑答案
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      将提交重新定位到 A 上,然后使用

      将它们一起压缩为一个提交
      git rebase -i HEAD~3
      

      【讨论】:

        【解决方案4】:

        通过 rebase 从 B 获取提交

        git rebase B

        现在将三个提交压缩为一个

        git rebase -i HEAD~3

        【讨论】:

          猜你喜欢
          • 2011-03-09
          • 2019-12-07
          • 2016-09-29
          • 2020-08-19
          • 2010-12-05
          • 2011-02-01
          • 1970-01-01
          相关资源
          最近更新 更多