threads / discuss / 6825

Stupid question on getting branch from yesterday

Subject: Stupid question on getting branch from yesterday

## tl;dr

9 messages between Feb 14, 2007 and Feb 14, 2007.

replies: 8people: 5as markdown or json

Bill Lear· Feb 14, 2007, 19:38 UTC · lore

I have not yet figured this one out: I have not tagged anything, but know that I checked in something lame sometime between now and two days ago. How do I get my working repo to be that as it was, say, yesterday?

Do I do:
% git log --since="2 days ago"
parse, the output for the commit I want, and then do
% git reset <SHA>
or would I do
% git reset --soft <SHA>
or something else?
Bill
Shawn O. Pearce· Feb 14, 2007, 19:49 UTC · re: Bill Lear · lore

Re: Stupid question on getting branch from yesterday

Bill Lear <rael@zopyra.com> wrote:
Show 11 quoted lines
> I have not yet figured this one out: I have not tagged anything, but
> know that I checked in something lame sometime between now and two days
> ago.  How do I get my working repo to be that as it was, say, yesterday?
> 
> Do I do:
> 
> % git log --since="2 days ago"
> 
> parse, the output for the commit I want, and then do
> 
> % git reset <SHA>

No. This would update your branch and your index to <SHA>, but leave your working directory alone. That's not what you want here.

Use `git checkout <SHA>` which will detach your HEAD and seek to
the commit, leaving your current commit alone.  Later you can get
back by `git checkout oldbranch`.
 
-- 
Shawn.
Junio C Hamano· Feb 14, 2007, 19:54 UTC · re: Shawn O. Pearce · lore

Re: Stupid question on getting branch from yesterday

"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 19 quoted lines
> Bill Lear <rael@zopyra.com> wrote:
>> I have not yet figured this one out: I have not tagged anything, but
>> know that I checked in something lame sometime between now and two days
>> ago.  How do I get my working repo to be that as it was, say, yesterday?
>> 
>> Do I do:
>> 
>> % git log --since="2 days ago"
>> 
>> parse, the output for the commit I want, and then do
>> 
>> % git reset <SHA>
>
> No.  This would update your branch and your index to <SHA>, but
> leave your working directory alone.  That's not what you want here.
>
> Use `git checkout <SHA>` which will detach your HEAD and seek to
> the commit, leaving your current commit alone.  Later you can get
> back by `git checkout oldbranch`.

Ah, I thought Bill was talking about getting rid of lame one, but now when I re-read his message, I think he is talking about going there to take a look, not necessarily wanting to discard or alter history.

Sorry, Bill, if that is the case, forget what I said about reset/revert/rebase in the other message.

Bill Lear· Feb 14, 2007, 20:24 UTC · re: Shawn O. Pearce · lore

Re: Stupid question on getting branch from yesterday

On Wednesday, February 14, 2007 at 14:49:19 (-0500) Shawn O. Pearce writes:
Show 19 quoted lines
>Bill Lear <rael@zopyra.com> wrote:
>> I have not yet figured this one out: I have not tagged anything, but
>> know that I checked in something lame sometime between now and two days
>> ago.  How do I get my working repo to be that as it was, say, yesterday?
>> 
>> Do I do:
>> 
>> % git log --since="2 days ago"
>> 
>> parse, the output for the commit I want, and then do
>> 
>> % git reset <SHA>
>
>No.  This would update your branch and your index to <SHA>, but
>leave your working directory alone.  That's not what you want here.
>
>Use `git checkout <SHA>` which will detach your HEAD and seek to
>the commit, leaving your current commit alone.  Later you can get
>back by `git checkout oldbranch`.
Ah, ok, then, you can use checkout with the SHA...

Junio, I was talking about just getting back to "lame" and inspecting, fixing, etc., not getting rid of things back to then.

Bill
Bill Lear· Feb 14, 2007, 20:28 UTC · re: Shawn O. Pearce · lore

Re: Stupid question on getting branch from yesterday

On Wednesday, February 14, 2007 at 14:49:19 (-0500) Shawn O. Pearce writes:
>...
>Use `git checkout <SHA>` which will detach your HEAD and seek to
>the commit, leaving your current commit alone.  Later you can get
>back by `git checkout oldbranch`.
BTW, we are still using 1.4.4.1.  This will work with that?

Another BTW: this seems very similar to something that you would tackle with git bisect (haven't used that yet), but as I understand it, git bisect works on tags(??).

Sort of what I had in mind:

% git bisect start % git bisect good --date="2 days ago" % git bisect bad master [...]

Bill
Jeff King· Feb 14, 2007, 20:36 UTC · re: Bill Lear · lore

Re: Stupid question on getting branch from yesterday

On Wed, Feb 14, 2007 at 02:28:21PM -0600, Bill Lear wrote:
Show 5 quoted lines
> >Use `git checkout <SHA>` which will detach your HEAD and seek to
> >the commit, leaving your current commit alone.  Later you can get
> >back by `git checkout oldbranch`.
> 
> BTW, we are still using 1.4.4.1.  This will work with that?
No. Detached HEAD is a 1.5 thing.
> Another BTW: this seems very similar to something that you would
> tackle with git bisect (haven't used that yet), but as I understand
> it, git bisect works on tags(??).

It can work on arbitrary commits. You can either pick the commit out of git-log or gitk manually, or you can use your reflog:

  git bisect start
  git bisect good master@{2.days.ago}
  git bisect bad
-Peff
Junio C Hamano· Feb 14, 2007, 19:50 UTC · re: Bill Lear · lore

Re: Stupid question on getting branch from yesterday

Bill Lear <rael@zopyra.com> writes:
Show 17 quoted lines
> I have not yet figured this one out: I have not tagged anything, but
> know that I checked in something lame sometime between now and two days
> ago.  How do I get my working repo to be that as it was, say, yesterday?
>
> Do I do:
>
> % git log --since="2 days ago"
>
> parse, the output for the commit I want, and then do
>
> % git reset <SHA>
>
> or would I do
>
> % git reset --soft <SHA>
>
> or something else?
Do you mean you have something like this:
 ---o---o---o---o---o---*---o---o HEAD
        ^               ^  
     two days           lame
     ago
and want to revert the lame one, or do you mean
 ---o---o---o---o---o---*---*---* HEAD
        ^               ^   ^   ^
     two days           lame
     ago

all are lame after certain point and want to discard all of them?

If the latter, probably "reset --hard <first-lame-one>^" (i.e. the parent of the first lame one) is what you want.

If the former, you may want to "git revert <lame>" or "git rebase --onto <lame>^ <lame>".

Linus Torvalds· Feb 14, 2007, 21:13 UTC · re: Bill Lear · lore

Re: Stupid question on getting branch from yesterday

On Wed, 14 Feb 2007, Bill Lear wrote:
Show 12 quoted lines
>
> I have not yet figured this one out: I have not tagged anything, but
> know that I checked in something lame sometime between now and two days
> ago.  How do I get my working repo to be that as it was, say, yesterday?
> 
> Do I do:
> 
> % git log --since="2 days ago"
> 
> parse, the output for the commit I want, and then do
> 
> % git reset <SHA>

No, use that only if you want to throw away everything you did after that particular point.

If you just want to go and look at it more closely, with git-1.5 you do
	git checkout <SHA>

which will just detatch your HEAD from any current branch, and just move you there. But with an older git that doesn't like the detached state, you'd could instead do

	git checkout -b nonlame-branch <SHA>

which actually creates a new branch with the <SHA> as the beginning point, and switches to it. That will work with any version (including 1.5, of course).

You can then decide to re-do the branch without the lame commit. One particularly simple thing to do (if it's just one lame commit, and you don't want to *remove* it, but just fix it up a bit) is to literally check out the tip of tree juat AT the lame commit, and then you can use

	git commit --amend
to actually change it.
So depending on what your situation is, this sequence actually works:
	#
	# Create and check out a "fixes" branch that has the 
	# known-broken commit as its head commit
	#
	git checkout -b fixes <BROKEN-COMMIT>
	.. edit edit edit to fix the broken commit ..
	#
	# Then, just _replace_ the broken commit with the fixed state
	# by doing a "git commit --amend"
	#
	git commit -a --amend
	#
	# ok, now the "fixed-branch" is in good shape, but we
	# want to re-surrect our original 'master' branch WITH the 
	# fix, and based on the fixed branch, so we rebase the
	# master branch# _onto_ the fixed state in "fixes", with
	# the broken commit (that we do _not_ want to include) as
	# the base.
	#
	git rebase --onto fixes <BROKEN-COMMIT> master

Somebody else should verify that "git rebase" thing. I still find the syntax for that thing rather illogical for these kinds of things. Possibly because I never do it myself.

		Linus
Junio C Hamano· Feb 14, 2007, 21:25 UTC · re: Linus Torvalds · lore

Re: Stupid question on getting branch from yesterday

Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 27 quoted lines
> So depending on what your situation is, this sequence actually works:
>
> 	#
> 	# Create and check out a "fixes" branch that has the 
> 	# known-broken commit as its head commit
> 	#
> 	git checkout -b fixes <BROKEN-COMMIT>
>
> 	.. edit edit edit to fix the broken commit ..
>
> 	#
> 	# Then, just _replace_ the broken commit with the fixed state
> 	# by doing a "git commit --amend"
> 	#
> 	git commit -a --amend
>
> 	#
> 	# ok, now the "fixed-branch" is in good shape, but we
> 	# want to re-surrect our original 'master' branch WITH the 
> 	# fix, and based on the fixed branch, so we rebase the
> 	# master branch# _onto_ the fixed state in "fixes", with
> 	# the broken commit (that we do _not_ want to include) as
> 	# the base.
> 	#
> 	git rebase --onto fixes <BROKEN-COMMIT> master
>
> Somebody else should verify that "git rebase" thing.
Looks fine.

← back to recent threads