Esenbek Kydyr uulu
Esenbek Kydyr uulu

Reputation: 1623

Git: keep specific files unmerged

Is it possible to keep some file unmerged all the time?

What I want is:

If there are two branches (A) and (B), and they have the same file. For example,

In branch (A) the file "setup" has the following:

this is setup
in a branch A

In branch (B) the file "setup" has the following:

this is setup
in a branch B

These branches don't have uncommitted files (Different commits for the same files in different branches).

The GOAL is to keep these files not touched after merging these branches.

The solutions in How to tell Git to always select my local version and Prevent merging a file from master with Git don't work for this. Because they work only when there's a conflict while merging them. (Well, yes there's going to be a conflict if we merge these two branches and it works for once. But if we merge (A) to (B), then (B) to (A), then the files become the same in both branches)

Does GIT have this kind of possibilities?

Upvotes: 3

Views: 976

Answers (5)

pjmorse
pjmorse

Reputation: 9304

One option is git update-index --assume-unchanged [file] which will ignore changes to the file when staging and committing but will leave it in the repository. This is a dangerous command because you'll need to remember you've assumed a file is unchanged when you do want to commit changes. Also, I'm not entirely sure how this will behave with a merge.

Upvotes: 0

Philip Oakley
Philip Oakley

Reputation: 14101

A bit long winded, but use the --no-commit for your initial merge step, and then checkout the original file to ensure it hasn't been overwritten, and then commit.

There is also a "pre-merge hook" dicussion on the git mailing list at the moment, this may also give you some options. git list

You could also try looking at the git source code and adding a .gitdonotmerge file (to the same directory) along the lines as the .gitignore (re-use all that existing code;-) and update the merge stratgetgy options so that this moderately common hassle gets fixed. The joys of scratching your own open source itch!

Upvotes: 1

Moamen
Moamen

Reputation: 706

make a .gitignore file in the directory where the file exist and just put the file name in it!

then run the commend

git rm -cached path_to_setup.file

So, It will ignore the file in all the operations like merge, pull, push, ...

more infromation: https://help.github.com/articles/ignoring-files

Upvotes: 1

VonC
VonC

Reputation: 1329662

If you really need to keep them different from master and development branches, I recommend the second option mentions in Ikke's answer, and version 2 values files (one for master, and one for dev branch), plus a template file.

Having several value files means they won't be merge issue between branches (each user modify only the value file relevant to the current branch).
The template file is there to help a content filter driver to generate on checkout a private file which represent the actual config file (with the right syntax, from the template file, and the right values, using the right value file, after the current branch)

filter driver

Upvotes: 1

Ikke
Ikke

Reputation: 101261

No, there is no easy way in git to do this, because of how git treats merges.

I might be wrong, but it seems you want to keep config files from getting merged. Is that right? Because there are better / other ways to deal with config files.

This page explains some solutions how to deal with several situations.

Summary:

  • If you can modify your program, let others override your config files which aren't tracked
  • If you can't modify the program, don't track the config file itself, but track a template instead.

Upvotes: 4

Related Questions