How do I merge a git branch that results in a single commit (such as using --squash) but allowing future merges without conflicts?

I have a branch with many commits starting from its creation and would like to do one commit merge to move it back to master using a single commit. Therefore the only solution I know is to use git merge --squash branchname

. This works well, but if someone adds more commits to branchname

, and I merge it back into master, I get conflicts from the initial new commits on branchname

. How can I prevent merge conflicts while keeping only one commit in master

per merge? I have considered using it git merge --no-ff

, but still translates all commits from branchname

to master

.

+3


source to share


1 answer


echo $(git rev-parse $result $result^ $merged) > .git/info/grafts
git merge topic

      

where $result

is the commit created by the squok merge and $merged

is the commit you merged with (i.e. the given git checkout master; git merge topic

one $result

is master

after the merge, and $merged

is the one topic

after the merge).

The file info/grafts

contains temporary overrides of repo-local pedigrees. Echo over the entries, only in this repo that the squash merge result also has a squash commit merged as its parent, meaning it records the exact history of the merge. Unrecorded merges only work if subsequent merges of the two branches still see the merged changes in the same way.

Don't forget that rebase and filter-branch will also see the grafted pedigree, and if they overwrite a commit $result

, they will write that pedigree in the new commit.




Of course, for merging feature branches, it is generally simply not customary to do this without writing them down, because that makes it impossible for git (or any vcs) to always find the correct merge base. Many unrecorded merges do not leave the correct merge base in history at all, you have to force it to get a good merge later. The Cherry-picks and squash merges are great as long as the technical debt is paid off by the recorded merge before further changes obscure the coincident shifts.

If the story you're merging is ugly, you'll love the interactive rebase. This allows you to create a commit history, which you would if you had the foresight to do it that way. Clearing changes for publication is a fundamental part of the workflow in many, many projects.

0


source







All Articles