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

Re: Commit to wrong branch. How to fix?

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Sep 4, 2009, 16:19 UTC
Message-ID
<4AA13DF4.4050604@drmicha.warpmail.net>
In-Reply-To
<88A0A7C2-7DCB-45A3-B196-BED2A8AC9405@googlemail.com>
Howard Miller venit, vidit, dixit 04.09.2009 17:54:
Show 8 quoted lines
> I commited to the wrong branch and I can't figure out what to do. To  
> make matters worse I then did 'git reset HEAD^' which has made things  
> much worse. It didn't remove the commit and now I can't change  
> branches. I'm utterly confused. Any help much appreciated!
> 
> Moral - use git status liberally and read it carefully before doing  
> anything. A 'git undo" command would be great is someone is feeling  
> generous :-) 
Whatever happens, don't panic ;)

Let's say "geesh" is the branch on which you committed by mistake, and which you have reset.

git reflog geesh

which show you what has happened to that branch lately. In particular, it will list the "lost" commit. (Most probably it is the same as geesh@{1}.)

git tag sigh sha1ofthatcommit

will assign the tag "sigh", so that it won't get lost by doing "git gc" or such. Now you can lean back!

Next step is committing "sigh" to the right branch. Depends on how you arrived at that commit. Did you commit the complete tree you wanted, or did you apply a change to geesh which you rather had wanted applied to some other branch?

Michael
Previous: Howard MillerNext: Erik Faye-Lund
Message 2 of 7 in “Commit to wrong branch. How to fix?”
  1. Howard MillerSep 4, 2009
  2. Michael J GruberSep 4, 2009
  3. Erik Faye-LundSep 4, 2009
  4. Michael J GruberSep 5, 2009
  5. Howard MillerSep 4, 2009
  6. Howard MillerSep 4, 2009
  7. Jakub NarebskiSep 4, 2009

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.