Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge take mine on everything [duplicate]

Tags:

git

merge

Is there a git merge command that merges another branch into the current branch, but doesn't change any files?

Or in other words, I want to create a new commit on branch A with:

  • The same tree (files) as latest commit on branch A
  • Parent commit should be latest commit on branch A
  • Other parent commit should be latest commit on branch B

Consider two long running branches one mine, one theirs. I want to merge their branch onto my branch, but since the code is effectively doing the same, I want to mark it as merged. The next time I'm merging again, it will not look back further than the merge commit that will be created in this process.

I know about -X mine/--strategy-option=mine but that will only kick in when there's an actual merge conflict. No added/deleted files should be applied on my branch.

like image 836
Caramiriel Avatar asked Sep 19 '17 21:09

Caramiriel


1 Answers

If you're absolutely certain you don't want the theirs, you could perform the merge without committing, then checkout mine as-is, then complete the merge commit.

git merge --no-commit their-branch
git rm . -rf
git checkout HEAD -- .
git commit

The git checkout HEAD -- . will overwrite any conflicted or automatically modified files. Performing a git status at this point should reveal that nothing is modified, but that you are still mid-merge. The commit then completes your non-merge merge.

Edit: git rm . -rf

Originally, I had omitted any part of this workflow capable of removing entirely new files from theirs, as git checkout HEAD -- . would leave these intact.

The line git rm . -rf ensures that every file known to git at that time is removed. This will include removing any file which existed in theirs but not ours. We will then checkout only those from ours, and commit the resulting empty merge.

like image 88
Robin James Kerrison Avatar answered Sep 28 '22 13:09

Robin James Kerrison