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

Re: Recovering from commit --amend in rebase --interactive

From
Boaz Harrosh <bharrosh@panasas.com>
Date
Jun 1, 2010, 09:48 UTC
Message-ID
<4C04D78A.2090103@panasas.com>
In-Reply-To
<alpine.DEB.2.00.1006011022030.2352@ds9.cixit.se>
On 06/01/2010 12:27 PM, Peter Krefting wrote:
Show 14 quoted lines
> Hi!
> 
> I am a frequent user of rebase --interactive, and sometimes I do change a 
> commit to "edit", which presents me with an already committed change, which 
> I can fix up, and do "git commit --amend" on.
> 
> However, sometimes I get conflicts during rebase. In some cases I have 
> already seen that conflict, so rerere handles it for me. I am still dropped 
> out of rebase to manually add the fixes, though.
> 
> The problem now is that is way too easy to just do a "git commit --amend" 
> like in the case above, and thus overwriting the previous commit 
> unintentionally.
> 
The prints are clear enough.

If stop do to "edit" then it prints ... you do: git commit --amend git rebase --continue

If stop do to merge-conflict it prints ... you do: git add ... (Note no commit command) git rebase --continue

You should be getting used to it after a while, I promise you
Show 7 quoted lines
> Is there an easy way of working around the issue?
> 
> 
> Last time this happened to me, I *did* notice my mistake as I entered the 
> editor, since it came up with the previous commit's message. However, as the 
> commit message file was in a good shape, I found no way to break out of the 
> amend. 

What?!? no, why. Just empty out the message at editor and save. It will abort any commit and do nothing. (For example with kwrite, ctrl-a, delete, ctrl-s, exit)

It does not matter if the commit as entered some default text for you or not. When editor is done if file is empty (or all comments) then it will abort and do nothing. Do not worry. The original commit is un affected. The message is just extracted from the original commit put to a tmp file and enter into editor. (its just a commit -c after all)

Show 6 quoted lines
> I ended up using "git reflog" to find out what I overwrote, then "git 
> diff $commitid > savedpatch" to remember what the change that I mistakenly 
> amended was, then "git checkout $commitid" and "git apply savedpatch" and 
> "git add" on the changed files. What I am wondering if there is an easier 
> way of recovering?
> 
Boaz
Previous: Peter KreftingNext: Peter Krefting
Message 2 of 8 in “Recovering from commit --amend in rebase --interactive”
  1. Peter KreftingJun 1, 2010
  2. Boaz HarroshJun 1, 2010
  3. Peter KreftingJun 1, 2010
  4. Jan KrügerJun 1, 2010
  5. Ævar Arnfjörð BjarmasonJun 1, 2010
  6. Junio C HamanoJun 2, 2010
  7. Ævar Arnfjörð BjarmasonJun 3, 2010
  8. Gabriel FilionJun 1, 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.