3

I'm starting now to adopt Git for my personal workflow at an SVN office, so git-svn is a tool I'm going to be relying on heavily. One issue I've come across that I don't know how to resolve is how to ignore in one direction.

The specific use case for me is that our ant build file references things like svn and svnversion. Obviously, if I'm using git-svn, I'm not planning on using either of those. I have replaced them in my local build.xml with git equivalents, which are working just fine.

However, I clearly don't want to commit that change in a git svn dcommit. I want to keep this change locally, and commit it locally so I don't lose it, but I don't want it to ever get committed back to the main SVN repo, because it will break pretty much the entire company's use of SVN, if I do. A similar case using SVN alone is presented in this question.

Is there any solution that would allow me to commit build.xml locally, continue to take build.xml changes from SVN (which has a lot of stuff not related to SVN as well), and never commit it back up using dcommit, without jumping through hoops every time I try to commit?

Community
  • 1
  • 1
Matt D
  • 1,476
  • 3
  • 17
  • 26

1 Answers1

5

Yes, you can.

As you noted, you can't gitignore files that are already tracked. But what you can do is tell your index that it should pretend that no changes exist for certain files:

git update-index --assume-unchanged <file>

If you want to stop ignoring changes for that file (for example, because you made a change to build.xml that you do need to share with other team members), then use:

git update-index --no-assume-unchanged <file>

Warning: if you directly add the file with git add <file>, it will assume that you really mean that you want to add that file, and the --assume-unchanged directive will be ignored.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
  • This does seem to work, but my concern here is that technically I wouldn't be committing it to the Git repo, right? I want it committed to the Git repo (I don't want to have to make those changes again, if somehow they get reverted/deleted locally), but I want git svn to ignore them. I don't like the idea of having working changes that aren't committed to anything. But it would work as one potential solution. Thanks! – Matt D Mar 08 '12 at 17:14
  • You can't do that, and with good reason. If it were possible, then you'd be pushing commits whose hashes were different from the ones locally on your repo. That would be a big no-no and would violate the integrity of your repository, which is far worse than making an accidental commit. – John Feminella Mar 08 '12 at 17:39
  • Understood. Thanks for the quick explanation. I guess I'll just have to figure out a way to modify my workflow. I suppose I'll create a separate branch with JUST the "build.xml" modifications, and leave it open/tagged so that I can recover the files in case I make a mistake on any other branches. Thanks for the solution, John! – Matt D Mar 08 '12 at 22:29
  • Unfortunately, I have run into the issue that even though the file is assumed to be unchanged, git does not allow me to switch branches due to uncommitted changes. It's a shame, because this is one of the main things keeping me from adopting Git as a regular part of my workplace workflow. – Matt D Mar 18 '12 at 20:50