Stupid question on getting branch from yesterday
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
Quoted 11 lines · Bill Lear
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.
Signature · 1 line
Shawn.
Quoted 11 lines · On Wednesday, February 14, 2007 at 14:49:19 (-0500) Shawn O. Pearce writes:
Quoted 10 lines · Bill Lear
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
Quoted 8 lines
Quoted 1 line
% 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 bygit 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
Quoted 4 lines · On Wednesday, February 14, 2007 at 14:49:19 (-0500) Shawn O. Pearce writes:
...
Usegit checkout <SHA>which will detach your HEAD and seek to the commit, leaving your current commit alone. Later you can get back bygit 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
Quoted 5 lines · Bill Lear
Quoted 3 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 bygit checkout oldbranch.BTW, we are still using 1.4.4.1. This will work with that?
No. Detached HEAD is a 1.5 thing.
Quoted 3 lines
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
Quoted 11 lines · Shawn O. Pearce
Quoted 10 lines · Bill Lear
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
Quoted 8 lines
Quoted 1 line
% 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 bygit 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.
Quoted 10 lines · Bill Lear
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
Quoted 7 lines
% 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>".
Quoted 5 lines · Bill Lear
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?
Quoted 7 lines
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
Quoted 26 lines · Linus Torvalds
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
Quoted 1 line
Somebody else should verify that "git rebase" thing.
Looks fine.