Search code examples
gitgitignoregit-index

git - revert update-index/ignored file so I can change branch?


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?


Solution

  • 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.