For a personal project, I have two branches, one public and one private. I have one file (call a.b
) that I will be updating regularly on my private branch, but when I merge the private branch onto the public branch, I don't want a.b
updated. Is there a way to do this?
A branch specific git update-index --skip-worktree a.b
command would be ideal, but from what I can tell, this command propagates to all branches.
CodePudding user response:
You could try merging without the automatic commit, and then make the appropriate changes to a specific file before finalising the merge commit.
Step 1:
Merge without the commit (no-ff so git doesn't just move the branch).
git merge <name-of-branch> --no-commit --no-ff
Step 2:
Restore the file
git restore --source=<name-of-other-branch> a.b
Step 3:
Commit the merge (make sure to write an appropriate message)
git commit