3

I was trying to add an error log to my .gitignore file, and somewhere along the way read that I had to specifically untrack the file after adding it to .gitignore. Somehow, I wound up using this to do so:

git update-index --assume-unchanged Logs/Err.log

All looked well, until I went to switch to my develop branch to merge. I can't change branches. I get the following error:

Your local changes to the following files would be overwritten by checkout: Logs/Err.log

Yet when I run a git status --s from my current branch, I get "nothing to commit, working directory clean"

I screwed up somewhere. How can I "actually" ignore that error log? How do I revert back to my previous non-update-index command?

jleach
  • 7,410
  • 3
  • 33
  • 60

2 Answers2

1

Based on my own experience, doing a git update-index --assume-unchanged only works on the branch in which you execute it. It doesn't really change what the underlying index looks like, it only masks it for operations occurring on that branch. So when you switch branches, Git still "sees" the dirty file. If you want to switch branches, you can try the following:

git stash

or

git reset --hard HEAD

Of course, you should first undo the update-index:

git update-index --no-assume-unchanged Logs/Err.log
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Hmm, --no-assume-unchanged... I wonder how that differs from --add... I'll RTFM (as I should have done in the first place...) – jleach Jan 18 '16 at 03:46
  • What you do in your answer feels like a hack to me. Generally speaking, if you need to change branches and your working directory is dirty, you should either stash, commit, or reset. – Tim Biegeleisen Jan 18 '16 at 03:48
  • That makes two of us (I was working on it while you posted your answer, else I'd have done it your suggested way). In any case, the branch is merged correctly to dev and now deleted as it's not longer needed. Hopefully no hidden issues down the road... – jleach Jan 18 '16 at 03:50
  • but it said my working directory was clean... shouldn't `git status` show me any dirtiness? – jleach Jan 18 '16 at 03:51
  • You missed the point of my answer (and the documentation). When you go a `git update-index --assume-unchanged`, Git puts a mask over the file so that it does not show up in the index _on that branch_. However, the file is really still there in the index and when you try changing branches, voilla, the mask comes off, as it should. – Tim Biegeleisen Jan 18 '16 at 03:52
0

I'm not sure this is the "correct" answer, but here's how I resolved it (helpful that it was only an error log that was hardly critical...)

  1. Removed the file from .gitignore
  2. delete the file
  3. run git update-index --add Logs/Err.log
  4. commit the branch
  5. checkout to develop and merge
  6. back to previous feature branch

Looks well. I can add the Err.log now and it'll pick up the changes, so the branch is tracking it again. I'll remove the file, then add to .gitignore again, and all should be well.

Moral:

  1. Don't mess with things when you don't understand exactly what they do (update-index)
  2. Don't try to ignore a file that's already being traced.
jleach
  • 7,410
  • 3
  • 33
  • 60