Problems with merging after a git update-index –assume-unchanged
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.
- Why a file deleted and recreated on different location is shown as renamed file?
- Merge dev into master and take all code from dev branch
- Commit to develop branch directly in Git Flow?
- Bundling version control software with product
- Using SVN and Git side-by-side
- Can I configure git blame to always ignore certain commits? Want to fix git blame once and for all
What sould I do to avoid this? Should I use this command(git update-index assume-unchanged) in all the branches?
3 Solutions collect form web for “Problems with merging after a git update-index –assume-unchanged”
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:
- The file is no need to do version control any more. So you can add the file in
.gitignore, and use
git rm --cached filenameto untrack it.
- Need to do version control for the file. When you merge branch, you can use
git merge branchname -X ours/theirsto make the file has no effect.
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
You’d then need to add the now untracked file to your
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.
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
"user.home"/.m2. This is where they belong.