Suppose that, while on some branch branch-X
I add and commit a certain file, foo.txt
, and that this file is not being tracked by any other branch in the repo besides branch-X
.
I want to tell git
that, whenever branch-X
is merged into any other branch in the repository, the file foo.txt
should never be added.
I have tried doing this by, e.g., setting the following line in the appropriate .gitattributes
file
foo.txt merge=ours
...but the file keeps getting added whenever I run
git checkout otherbranch
git merge branch-X
I guess that the issue here is that there's no real "conflict" between the file foo.txt
in branch-X
, and "no file" in otherbranch
, so the merge strategy does not need to come into play. (BTW, this is why this question is not a duplicate, AFAICT: all related questions I've found refer to the case of conflicting files that exist in both branches of the merge, and the answers given to those questions don't seem to work for the case I'm presenting here.)
Also, at least in cases where the merge is a fast-forward, no new commit is done, so it's no use to run git-merge
with the --no-commit
option in the hopes of explicitly removing foo.txt
from the index.
I imagine that the mechanics underlying what I'm trying to do here would require translating the command
git merge branch-X
into the sequence
git branch branch-X-no-foo branch-X
git checkout branch-X-no-foo
git rm foo.txt
git commit -m 'pay no attention to the man behind the curtain...'
# or maybe
# git commit -C HEAD --amend
git checkout otherbranch
git merge branch-X-no-foo
I suppose I that I could write a script to wrap this sequence into an easy-to-type command, but I thought I'd ask if there's a better approach.