Git merge squash repeatedly

后端 未结 5 2138
暗喜
暗喜 2020-12-04 09:23

I\'m trying to have two branches with binary files in git - one \"development\" and one \"stable\". The development branch can have several changes of these files before I w

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 09:42

    The top voted answer effectively diffs the stable and the development branches and applies all changes missing in the stable as one commit. There is an alternative way to do this:

    $ git checkout stable 
    $ git diff stable development | git apply --index -   
    $ git commit
    

    Before you commit, you can review the staged files. If you want to abort the process after you applied the diff, you can just use basic commands to remove changes from index and working directory.

    $ git reset --hard
    

    You can repeat the process any number of times, since you are effectively just diff-ing the tips of both the branches each time you need to merge.

    Note that there is assumption here that applies to the other answer as well: there are no commits in the stable branch other than the ones that came from the development branch. If the same line were changed independently in both branches, unlike a regular merge, this approach would not give you a conflict. Instead, it would just override the changes in the stable branch with the ones in development.

    If you are concerned about this, each time you commit on stable, you can put the merged development commit hash range in the commit message. That way, you have some record, if you ever need to backtrack.

提交回复
热议问题