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

Re: Basic Git Questions

From
Thomas Rast <trast@student.ethz.ch>
Date
Dec 19, 2010, 23:15 UTC
Message-ID
<201012200015.17203.trast@student.ethz.ch>
In-Reply-To
<20101219230839.GM3264@localhost.localdomain>
Konstantin Khomoutov wrote:
Show 6 quoted lines
> > 2. Also sometime when the code is committed, I realize that I have
> > forgot to change or add a file. Is there a way we can we commit a file
> > to existing commit number with git log showing only the old git commit
> > number and not creating a new one for the last commit.
> `git commit --amend` does exactly that -- amends the last commit
> (pointed by the HEAD ref).

Let me add that you can fundamentally not edit any git object in any way without its ID (hash, sha1, whatever you call it) changing. All methods of "changing" commits, like amend, rebase, filter-branch etc. always create a new object. The trick is that, especially with amend, the branch is also changed to point to the new one, so unless you have already merged or pushed that commit, this is as close to "changing" as it gets.

Tv put this more eloquently as: "you can never change; you can only rewrite and forget".

If you *have* merged or pushed the commit, you shouldn't rewrite history. It's not that hard to fix up your local merges, but if you have pushed the history and others have started working with it, it's *very* annoying for them.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Konstantin Khomoutov
Message 3 of 3 in “Basic Git Questions”
  1. Parag KalraDec 19, 2010
  2. Konstantin KhomoutovDec 19, 2010
  3. Thomas RastDec 19, 2010

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.