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:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With