3

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?

Community
  • 1
  • 1
Esenbek Kydyr uulu
  • 1,553
  • 1
  • 14
  • 19
  • 1
    You are asking how to solve a solution, instead of how to solve a problem. Could you take a step back, and explain why you want / need this? Then we could give better advise on how to do things. – Ikke Sep 04 '12 at 10:57
  • Do you expect further changes in the files? – kan Sep 04 '12 at 10:57
  • yes. I expect further changes in this specific files and also in other files, which need to be merged as usual – Esenbek Kydyr uulu Sep 04 '12 at 11:49

5 Answers5

4

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.
Ikke
  • 99,403
  • 23
  • 97
  • 120
1

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is very useful, but unfortunately doesn't work in my case. Because I have apps running on different branches, and the config files are updated from time to time. The 'git checkout' is done only once, but then it 'pull's config file many times. – Esenbek Kydyr uulu Sep 04 '12 at 17:37
  • @EsenbekKydyruulu the `git pull` will trigger the checkout and the filter trigger. – VonC Sep 04 '12 at 18:05
1

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

Moamen
  • 706
  • 7
  • 19
1

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!

Philip Oakley
  • 13,333
  • 9
  • 48
  • 71
0

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.

pjmorse
  • 9,204
  • 9
  • 54
  • 124