Thread (4 messages) 4 messages, 3 authors, 2016-06-15

Re: git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03))

flat view

From: Christian Couder <hidden>
Date: 2016-06-15 22:48:23

On Friday 05 March 2010 17:25:21 Jonathan Nieder wrote:
1. Helping people new to git.

A person not very familiar with git comes to me asking how to undo
the last couple of commits.  After a quick conversation, it becomes
clear that the commits in question were not pushed out to any public
repository and that this person does not feel it would be useful to
publish the problem commits.

Currently, I would have to advise such a person to use

	git reset --hard HEAD^^

I would prefer to recommend

	git reset --keep HEAD^^

because if there are uncommitted changes then it will give a "needs
update" message (right?) and I can help the person to deal with it.
If the uncommited changes are in files that are not touched by the discarded 
commits then it will silently work and will keep your uncommited changes.
If the uncommited changes are in files touched by the discarded commits then it 
will fail with an error message like this:

error: Entry 'foo' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'HEAD^^'.

Best regards,
Christian.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help