0

My specific situation: Java program with an About class that is imported by a couple of other classes in the project. When compiling, the About.java file is auto-regenerated but otherwise it's never touched.

  • I don't want to remove the file from the repo and .gitignore it because that means when some one initially pulls down the repo, the About.java file is not there. Admittedly, this isn't the end of the world given that it will generate on their first compilation, but still, for that time being there are errors in the IDE, etc. I just don't like that. I want some compilable version of the file to be there, even though I don't care what its specific contents are (since they'll be overwritten upon compilation anyway).

  • After a compilation and regeneration in my local branch, I want git to ignore the fact that the file was changed vis-a-vis 'git status', 'git diff', 'git add -i', etc. so that my compilation's changes to it are not cluttering up my real check-ins.

  • After a compilation and regeneration in my local branch, I want to be able to switch to another branch and have git not worry about the fact that my current local branch has a changed About.java file. Just throw away the changes and move on to whatever About.java is in the branch I'm switching to.

I've tried using a combination of 'git update-index skip-worktree' on the file and then switching branches using 'git checkout -f' but it doesn't work. The checkout -f to switch branches complains that the entry for the About.java file is "not uptodate. Cannot merge."

The man for checkout -f says: "When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored."

That sounds like exactly what I want, but when I use it in the above scenario it still very much fails upon an unmerged entry. Why is that?

BTW, I've tried messing with 'git update-index --assume-unchanged' also, but still I can't get all three of the desired behaviors (base version that stays in the repo, when I make/check-in changes ignore the fact that that one file has changed, and allow me to change branches and truly do not fail because that one file is an unmerged entry) in play together

At present, I have behaviors 1 and 2 with skip-worktree and then when I want to change branches, I have to manually reset that one file first. Works, but it's very annoying to have to always do that. Is there any way to make checkout -f do what it's man page says it's supposed to do and get to the complete behavior that I want?

Michael
  • 325
  • 1
  • 3
  • 9
  • Relevant reading: http://stackoverflow.com/q/13630849/1256452 – torek Jul 01 '16 at 22:07
  • Possible duplicate of [git ignore files only locally](http://stackoverflow.com/questions/1753070/git-ignore-files-only-locally) – srage Jul 01 '16 at 22:37
  • I've read those above threads and indeed, as best I can tell, the behaviors I'm seeing from assume-unchanged and no-worktree are basically consistent with the information therein. The piece that's missing, from my perspective, is why checkout -f is not throwing away my local changes like its man says it's supposed to do. – Michael Jul 02 '16 at 23:22

1 Answers1

0

Please refer to: How to ignore files only locally in git?

git update-index --skip-worktree FILENAME
Community
  • 1
  • 1
srage
  • 990
  • 1
  • 9
  • 27
  • I'm not seeing any difference in behavior when adding the file to .git/info/exclude. As before, the assume unchanged gives me behaviors 1 and 2 that I listed, but not 3. checkout -f still fails because the About. java is "not uptodate. Cannot merge." – Michael Jul 02 '16 at 23:16
  • @Michael make sure to adapt the ignore rule. My example assumes that the file is in the top-level directory. – srage Jul 02 '16 at 23:20
  • Yes, I got that. I put the correct path to the file; it hasn't made a difference. – Michael Jul 02 '16 at 23:22
  • @Michael I read referenced question again; you need --skip-work-tree not - -assume-unchanged. A working implementation of that should definitely do the trick. Use git status to confirm changes. – srage Jul 02 '16 at 23:39
  • As I wrote in the question, --skip-worktree is what I tried first. I have tried them both just to be sure and neither one works. Regardless of which one of them I set, as soon as I do a compilation and the About.java changes, I am forbidden from checking out a different branch until I either revert the change, stash it or delete the file. git checkout -f refuses to throw away the change, despite the fact that that's exactly what it's supposed to do. – Michael Jul 04 '16 at 06:11
  • Perhaps you're not reading your standard error correctly? "not uptodate. Cannot merge" appears to be exclusively a git pull error. – srage Jul 04 '16 at 06:25
  • Confirm that git has the correct file permissions for About.java – srage Jul 04 '16 at 06:33
  • Exact command isssued: "git checkout -f development" Exact response received: "error: Entry 'src/java/com/wheelhouse/api/About.java' not uptodate. Cannot merge." git pulls are not involved and the file permissions are 644, same as all other source code files. – Michael Jul 04 '16 at 21:25