Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I make Bitbucket to always use latest version for a certain file in repo to resolve a conflict?

Sena Turku Cakmak
Contributor
November 26, 2024

Hello community,

There is a file in my repo that always causes conflict when I try to merge. I want Bitbucket to always use the code in incoming file for that spesific file, and not give a conflict for this spesific file. Is is possible to set this?

Thanks,

Sena

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 28, 2024

Hello @Sena Turku Cakmak ,

thank you for reaching out to the Community!

You can actually achieve that workflow directly using a git configuration, rather than a setting on Bitbucket.

For that you'll need to setup a git attributes file and a merge drive. Here's a step-by-step example:

  1. Create or Edit the .gitattributes File:

    • In the root of your repository, create a new file named .gitattributes if it doesn't exist already.

  2. Specify the Merge Strategy:

    • Add a line in the .gitattributes file for the specific file that always causes conflicts. Use the ours merge strategy, which tells Git to always favor the incoming version of the file during a merge. The line should look like this:

      path/to/your/file merge=ours
  3. Configure the Merge Driver:

    • You need to set up a custom merge driver in your Git configuration:

      git config --global merge.ours.driver true
  4. Commit and Push the Changes:

    • Commit the .gitattributes file to your repository and push the changes.

With this setup, Git will automatically resolve conflicts for the specified file by using the incoming version during a merge. Please note that this approach should be used carefully, as it will discard changes in the local version of the file during a merge.

I hope this helps! Let us know in case you have any questions.

Thank you, @Sena Turku Cakmak !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events