# cogito - how to drop a commit

3 messages from 2005-08-06 to 2005-08-11. Participants: Sam Ravnborg, Linus Torvalds, Petr Baudis.
Thread: https://gitlist.dev/t/1441

## Sam Ravnborg, 2005-08-06 22:34

Subject: cogito - how to drop a commit
Message-ID: <20050806223436.GA6495@mars.ravnborg.org>
URL: https://gitlist.dev/e/20050806223436.GA6495%40mars.ravnborg.org

```
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.

I do not mind to execute a few git commands, but for my daily usage I
expect cogito to hanle everything and dropping a commit has proved
useful for me from time to time, so I expect it be be implemented in the
porcelain somehow.

I have read the help for cg-seek - but it di not convince me to be what
I seeked.

	Sam

```

## Linus Torvalds, 2005-08-07 00:42

Subject: Re: cogito - how to drop a commit
Message-ID: <Pine.LNX.4.58.0508061727000.3258@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0508061727000.3258%40g5.osdl.org
In-Reply-To: <20050806223436.GA6495@mars.ravnborg.org>

```


On Sun, 7 Aug 2005, Sam Ravnborg wrote:
>
> 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

```

## Petr Baudis, 2005-08-11 21:59

Subject: Re: cogito - how to drop a commit
Message-ID: <20050811215952.GF25280@pasky.ji.cz>
URL: https://gitlist.dev/e/20050811215952.GF25280%40pasky.ji.cz
In-Reply-To: <20050806223436.GA6495@mars.ravnborg.org>

```
Dear diary, on Sun, Aug 07, 2005 at 12:34:36AM CEST, I got a letter
where Sam Ravnborg <sam@ravnborg.org> told me that...
> 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.
> 
> I do not mind to execute a few git commands, but for my daily usage I
> expect cogito to hanle everything and dropping a commit has proved
> useful for me from time to time, so I expect it be be implemented in the
> porcelain somehow.
> 
> I have read the help for cg-seek - but it di not convince me to be what
> I seeked.

cg-admin-uncommit, be sure to read --help first. Linus' pruning notes
apply as well, cg-admin-uncommit won't delete it from the database
(I personally don't care about that and never pruned so far).

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox

```
