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

Re: Git reset --hard with staged changes

From
Pierre-François CLEMENT <likeyn@gmail.com>
Date
Jun 10, 2014, 16:30 UTC
Message-ID
<CANWD=rWRT1iarnZzyd75g6gr0nyo3rrdH01j+Bjq0t4q2UUhhg@mail.gmail.com>
In-Reply-To
<871tuwss2p.fsf@fencepost.gnu.org>
2014-06-10 17:27 GMT+02:00 David Kastrup <dak@gnu.org>:
Show 28 quoted lines
> Pierre-François CLEMENT <likeyn@gmail.com> writes:
>
>> 2014-06-10 1:28 GMT+02:00 Junio C Hamano <gitster@pobox.com>:
>>> Pierre-François CLEMENT <likeyn@gmail.com> writes:
>>>
>>>> Hm, I didn't think of "git apply --index"... Makes sense for this
>>>> special use, but I'm not sure about the other use cases.
>>>
>>> Try merging another branch that tracks a file your current branch
>>> does not know about and ending up with conflicts during that merge.
>>> Resetting the half-done result away must remove that new path from
>>> your working tree and the index.
>>
>> Hm I see. Even though the documentation doesn't make it very clear
>> about what happens to such files, it turns out the scenario we
>> stumbled upon seems to be the special use case after all. Thanks for
>> shedding some light on this :) I wonder why does git-reset's hard mode
>> not always remove untracked files then?
>
> Because it never removes them?  Git only removes files once it tracks
> them.  This includes the operation of removing _and_ untracking them,
> like with git reset --hard.
>
> The only command which explicitly messes with untracked files is
> git-clean.
>
> --
> David Kastrup

Yeah sorry, I just noticed the emails on the definition of what are (un)tracked files (http://thread.gmane.org/gmane.comp.version-control.git/251071/focus=251151), as I didn't get them in my inbox for some reason. So staged files which aren't in HEAD are also considered tracked -- which explains it all. Someone told me that too on the "Git for human beings" Google Group, but I couldn't find a definition that backs this in the man pages (maybe the git-glossary would be a good place for it?), and the one from the Git-Scm book only confused me in thinking the opposite. Thanks for the clarification

-- Pierre-François CLEMENT Application developer at Upcast Social

Previous: David KastrupNext: Dale Worley
Message 7 of 9 in “Re: Git reset --hard with staged changes”
  1. Pierre-François CLEMENTJun 9, 2014
  2. David KastrupJun 9, 2014
  3. Pierre-François CLEMENTJun 9, 2014
  4. Junio C HamanoJun 9, 2014
  5. Pierre-François CLEMENTJun 10, 2014
  6. David KastrupJun 10, 2014
  7. Pierre-François CLEMENTJun 10, 2014
  8. Dale WorleyJun 10, 2014
  9. Junio C HamanoJun 10, 2014

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.