3

My coworker has asked me if he could ingore a file after he had committed it, as an example a pom.xml file, commonly used in maven projects.

I found out the git update-index --assume-unchanged can be useful in this situation. But when I try to merge from another branch, git is still tracking the ignored file and a conflict happens.

What sould I do to avoid this? Should I use this command(git update-index assume-unchanged) in all the branches?

G. Alves
  • 33
  • 4
  • `--assume-unchanged` probably wasn't the best tool for this job - [check out this answer that describes it's proper use](http://stackoverflow.com/a/23305143/297243) – Tom Jan 11 '17 at 12:13

3 Answers3

1

The command git update-index --assume-unchanged filename can’t be used in two branches, it’s a way to temporarily ignore a file for a while. When you modify the file, and then want to switch or merge to other branches, git will show error message for you because you have un-commit changes, that means you should use git update-index --no-assume-unchanged filename before switch or merge branch.

For your situation, you can refer below two ways:

  1. The file is no need to do version control any more. So you can add the file in .gitignore, and use git rm --cached filename to untrack it.
  2. Need to do version control for the file. When you merge branch, you can use git merge branchname -X ours/theirs to make the file has no effect.
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
0

As I commented - --assume-unchanged isn't the right tool for this job

According to the Git documentation the best way of doing this is to use git rm --cached <file>;

Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. In other words, you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your .gitignore file and accidentally staged it, like a large log file or a bunch of .a compiled files. To do this, use the --cached option

You'd then need to add the now untracked file to your .gitignore file.

For branches - you will have to manage the merging of your branches that do track this file to make sure it doesn't make it's way into the repository again. The easiest way would be to make this alteration in each branch prior to merging it.

Community
  • 1
  • 1
Tom
  • 4,257
  • 6
  • 33
  • 49
0

I found out the git update-index --assume-unchanged

This tells git not to compare the file in the working directory with the current repository state.

The merge on the other hand happens between to commits in the repository. therefore you still have conflicts if your merge with someone elses changes on the same file.


Your example why you need that feature is mavens project configuration file.

It feels to me that especially this file should not be ignored or otherwise excluded from the scm. So Why do you need that?

My guess is that you have defined properties in your pom that point to local resources. If so: move that properties the settings.xml in "user.home"/.m2. This is where they belong.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51