- merge One Branch into Another Branch normally (including
No-add-another-branch)
- stage deletion of
No-add-another-branch (using git rm No-add-another-beanch)
- amend the merge commit (
git commit --amend)
An alternative is to delete the file in a temporary branch before merging. This creates one extra commit but makes the merge cleaner and the history will be more obvious to read.
git checkout -b tmp OneBranch
git rm No-add-another-branch followed by git commit -m 'Remove the file before merging
git checkout AnotherBranch and git merge tmp
git branch -d tmp
The history should then look like this:
o--o--o--o Another Branch
/
o Remove the file before merging
/
o--o--o One Branch
If, instead of removing the file, you want to keep it unchanged, you can either replace step 2 of the first approach by git checkout AnotherBranch^ -- No-add-another-branch (i.e., restore its previous version before the merge), or replace step 2 of the second approach by git checkout AnotherBranch -- No-add-another-branch followed by git commit -m 'Make the file equal to Another Branch before merging'.