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

Re: cogito - how to drop a commit

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 7, 2005, 00:42 UTC
Message-ID
<Pine.LNX.4.58.0508061727000.3258@g5.osdl.org>
In-Reply-To
<20050806223436.GA6495@mars.ravnborg.org>
On Sun, 7 Aug 2005, Sam Ravnborg wrote:
Show 5 quoted lines
>
> I accidently commited too many files to my tree today, and now I want to
> drop the commit so I have logically separate commits.
> 
> What is the right way to do this - in cogito hopefully.

Not cogito, and this needs to be scripted, but if what you _want_ to do is undo the commit (in order to re-do it as several commits), here are the raw git commands necessary (you could make this "git-fix-script", and then "git fix" basically does the git equivalent of what "bk fix -C" did)

	# Set up
	#
	. git-sh-setup-script || die "Not a git archive"
	# Figure out the parent.
	#
	parent=$(git-rev-parse --verify HEAD^) || exit
	#
	# Update the index to be at that point in time and make HEAD 
	# point to it, but don't update the working tree contents (ie
	# the changes remain in the working tree, to be re-committed).
	#
	git-read-tree -f -m $parent && echo $parent > .git/HEAD

NOTE! The commit still _exists_, but the HEAD reference to it is now lost. If you want to save that as a broken branch, you can precede this with

	git branch broken-branch
which means that the broken point got saved off as "broken-branch".

And if you didn't do that (or if you _did_ do that, and later end up deciding to throw that branch away with a

	rm .git/refs/heads/broken-branch

or similar) then you can get rid of the stale and unreachable objects with a simple "git prune".

Be careful! "git prune" _will_ throw away all the objects that it can't find references to. You might want to run "git-fsck-cache --full --unreachable" first to get an idea of what it's going to throw away.

			Linus
Previous: Sam RavnborgNext: Petr Baudis
Message 2 of 3 in “cogito - how to drop a commit”
  1. Sam RavnborgAug 6, 2005
  2. Linus TorvaldsAug 7, 2005
  3. Petr BaudisAug 11, 2005

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.