git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Broken branch after git commit - tracked files in staging area can't be removed with restore --staged, or commit or stash

From
TKTorsten Krah <krah.tm@gmail.com>
Date
Jan 9, 2020, 10:49 UTC
Message-ID
<df169ee421429f8f0aa18a897a67677a2adf2b6b.camel@gmail.com>
In-Reply-To
<20200109093931.GA299671@coredump.intra.peff.net>
Am Donnerstag, den 09.01.2020, 04:39 -0500 schrieb Jeff King:
Show 15 quoted lines
> You should be able to do:
> 
>   git checkout your-branch
>   git reset --hard <original>
> 
> to go back to the state you were at (this is assuming you haven't
> built
> more commits on top, of course), and then repeat your steps. That
> should
> also clear out any breakage in the index, since "reset --hard" will
> invalidate the cache-tree as necessary.
> 
> If you need to find the commit id of that original commit, try
> looking
> in the reflog for your branch: git log -g your-branch
Hi Peff,

thanks that did work - but I had to "rm .git/index" before the hard reset to get those "deleted" ones removed from the staging area, after that I was able to use "git reset -- $files" and that was working like expected. Without deleting that index file I could run the hard reset but running "git status" afterwards insisted every time on this:

On branch feature-2182
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	deleted:    docker-compose.gerrit.yml
	deleted:    docker-compose.reverseproxy.yml
	deleted:    docker-compose.yml
	deleted:    docker-seccomp.json
	deleted:    gradle.properties
	deleted:    settings.gradle
Those only vanished after deleting the index file.

The "settings.gradle" is part of my changeset and listed in the "commit". But those other 5 files listed I had never touched in my commit - I don't know why they are in the staging area here - maybe some other edge case of the git restore bug - but just a "git hard --reset $hash" did not clear those.

Torsten
Previous: Jeff King
Message 13 of 13 in “Broken branch after git commit - tracked files in staging area can't be removed with restore --staged, or commit or stash”
  1. Torsten KrahJan 7, 2020
  2. Torsten KrahJan 7, 2020
  3. Torsten KrahJan 7, 2020
  4. Jeff KingJan 8, 2020
  5. Torsten KrahJan 8, 2020
  6. Torsten KrahJan 8, 2020
  7. Jeff KingJan 8, 2020
  8. restore: invalidate cache-tree when removing entries with --stagedJeff King, Jan 8, 2020
  9. Junio C HamanoJan 8, 2020
  10. Dennis KaarsemakerFeb 5, 2020
  11. Torsten KrahJan 8, 2020
  12. Jeff KingJan 9, 2020
  13. Torsten KrahJan 9, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.