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

Re: Git reset --hard with staged changes

From
Junio C Hamano <gitster@pobox.com>
Date
May 31, 2016, 06:02 UTC
Message-ID
<xmqqvb1u7okk.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<4067AC3B-D369-4E86-9EB9-ED19FD362E2D@yotamgingold.com>
Yotam Gingold <yotam@yotamgingold.com> writes:
Show 10 quoted lines
> I read Junio's enumerations of the situations, and I appreciate that the
> current behavior of git reset --hard cannot be changed because of the
> many tools that rely on the current behavior. After reading it, I have
> modified my proposed amendment to the git reset --hard documentation:
>
>     A file is considered tracked if it exists in a prior commit or in the
>     staging area. Note that a newly added file not in any prior commit will be
>     removed. This is useful for aborting a failed merge.
>
> Shall I submit a patch?

I think the root cause of the confusion is that the description of "reset --hard" uses an undefined word "tracked", which does not appear anywhere else in "git reset --help".

A better rewrite is probably a one that does not to use such a fuzzy word that is not even in official Git lingo (there is no glossary entry for it).

 Documentation/git-reset.txt | 10 ++++++++--
 t/perf/perf-lib.sh          |  4 +++-
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
index 25432d9..c4cc035 100644
--- a/Documentation/git-reset.txt
+++ b/Documentation/git-reset.txt
@@ -65,8 +65,14 @@ If `-N` is specified, removed paths are marked as intent-to-add (see
 linkgit:git-add[1]).
 
 --hard::
-	Resets the index and working tree. Any changes to tracked files in the
-	working tree since <commit> are discarded.
+	Reset the index and the working tree to be identical to the
+	tree of the given <commit> (defaults to HEAD) by discarding
+	the changes made to them relative to <commit>.  Paths
+	modified in the index and in the working tree are reset to
+	what is recorded in <commit>.  Paths removed in the working
+	tree and in the index are resurrected from <commit>.  Paths
+	added to the index and the working tree since <commit> are
+	removed.
 
 --merge::
 	Resets the index and updates the files in the working tree that are
Previous: Yotam GingoldNext: Christian Couder
Message 7 of 8 in “Re: Git reset --hard with staged changes”
  1. Yotam GingoldMay 23, 2016
  2. Junio C HamanoMay 23, 2016
  3. Christian CouderMay 23, 2016
  4. Junio C HamanoMay 23, 2016
  5. Christian CouderMay 24, 2016
  6. Yotam GingoldMay 30, 2016
  7. Junio C HamanoMay 31, 2016
  8. Christian CouderMay 31, 2016

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.