How to ignore specific files during a merge?
Git provides flexible configuration. The server-side does not support ignoring files during a merge. However, you can configure rules to ignore specific files when you perform a local merge.
Ignore files during a local merge
If a review is required, create a merge request in the web UI and use the platform's features for automated or manual review. After the review is complete, do not merge from the UI. Instead, merge the approved content locally. Before you merge, configure the ignore rules.
The following example describes the configuration procedure:
Prevent the file demo.txt in the root directory of the dev branch from being merged into the master branch.
Prevent the file /common/src/main/resources/demo.yml in the dev branch from being merged into the master branch.
To do this, follow these steps:
Run the following command in the root directory to enable the file ignore setting:
git config merge.ours.driver trueOn the dev branch, create and commit a .gitattributes file with the following content:
demo.txt merge=ours /common/src/main/resources/demo.yml merge=oursSwitch to the master branch and perform the merge:
git checkout master git merge dev
To prevent a file change in the dev branch from being merged into the master branch, the file in the master branch must have a later modification time. In this example, first modify and commit the file in the dev branch. Then, modify and commit the file in the master branch. Finally, merge the branches.