1

I started a commit in Git-Extensions to add changes to a file myfile. Then I guess I clicked somewhere I didn't mean to and now any changes I make to myfile are ignored by git. I have closed git-extensions and am only operating in a powershell.

If I change the file, git status shows no difference. But if I add the file with git add myfile (despite having no reason to assume that it is not tracked, it was changed in the last commit) then git status still doesn't show it. If I delete .gitignore then .gitignore will show up in git status but myfile still won't.

If I change the file on the remote and do git pull, git will acknowledge my local file:

error: Your local changes to the following files would be overwritten by merge:
        myfile
Please commit your changes or stash them before you merge.
Aborting
Updating 09ad056..eef460f

But I can't commit (because I cannot add) and git stash wont't stash myfile. I can delete myfile and then git pull works but after that I am where I started: no local changes are acknowledged.

I've never observed this behaviour and I cannot reproduce it. How can I debug this further and resolve the issue?

Now that the solution is found:

I must have accidentally clicked here
enter image description here

peer
  • 4,171
  • 8
  • 42
  • 73
  • This is expected. If a tracked file has uncommitted changes git does not want to overwrite it. --- What does _"I started a commit in Git-Extension"_ mean? – evolutionxbox Apr 06 '21 at 15:01
  • @evolutionxbox git-extensions is a gui for windows where the error initially occurred, for debugging I moved to the shell. If I change a tracked file I do expect it to show up in git status under `Changes not staged for commit` – peer Apr 06 '21 at 15:04
  • Maybe the issue is with that GUI? Consider cloning the repo somewhere else and trying the steps again? – evolutionxbox Apr 06 '21 at 15:05
  • @evolutionxbox I suppose cloning anew would work, but I'm wondering why the error still occurs with plain git, after I closed the GUI. – peer Apr 06 '21 at 15:10
  • Without being able to see the state of the repo I couldn't tell you. Maybe someone else can? (@torek) – evolutionxbox Apr 06 '21 at 15:11
  • To debug the effects of `gitignore` files : run `git check-ignore -v myfile` – LeGEC Apr 06 '21 at 16:04
  • In addition to what @LeGEC is recommending, paste in your question the output of: `git status`. What I expect is that your file was originally added to the history, shows as being modified now in `git status`, and you can't commit it because is also added to `.gitignore`. So, you should remove that particular rule from `.gitignore`, create a backup of the file, use `git checkout -- ` to restore the change, `git rm ` to remove it from history, and then restore your file and uncomment the rule from `.gitignore`. – azbarcea Apr 06 '21 at 16:18
  • @peer : did `git check-ignore -v myfile` output something ? If nothing is shown there : you can check for the very secret "assume-unchanged" flag : https://stackoverflow.com/a/17195901/86072 . – LeGEC Apr 06 '21 at 19:46
  • 1
    @LeGEC That's it! `myfile` is `skip-worktree` according to `git ls-files -v` – peer Apr 06 '21 at 22:22
  • ok, I'm a bit surpised a rogue click in git extensions triggered that, but the facts are there – LeGEC Apr 06 '21 at 22:25

2 Answers2

2

There are two not very publicized flags, assume-unchanged and skip-worktree, which can be set on files in a local repository, and "hide" them from local versioning.

These flags can be set/unset with git update-index, and you can spot files who have one (or both) of these flags using git ls-files -v, and inspecting the status letter at the beginning of each line.

From our discussion in the comments : obviously, some action set that flag on your file.
You now know how to spot those files, and how to unset that flag.

I'm not fluent in Git-Extensions, you may find a way to do the same actions (set/unset/list) from its GUI.


This SO question packs a pretty complete reference --assume-unchanged :

# set the flag :
git update-index --assume-unchanged <file>

# unset the flag :
git update-index --no-assume-unchanged <file>

# check for lines where the status letter is in *lowercase* :
git ls-files -v

# using grep :
git ls-files -v | grep '^[a-z]'

--skip-worktree works with similar commands :

# set the flag :
git update-index --skip-worktree <file>

# unset the flag :
git update-index --no-skip-worktree <file>

# check for lines where the status letter is 'S' (or 's') :
git ls-files -v

# using grep :
git ls-files -v | grep '^[Ss]'
LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

As you've already discovered there are few ways to ignore changes to a file in git and Git Extensions.

These options are also exposed in the Commit dialog via a context menu for each file: enter image description here

Also you can change the filter to see more or less: enter image description here

RussKie
  • 1,630
  • 11
  • 20