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

Re: Stupid question on getting branch from yesterday

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 14, 2007, 21:13 UTC
Message-ID
<Pine.LNX.4.64.0702141250300.20368@woody.linux-foundation.org>
In-Reply-To
<17875.25882.784307.731860@lisa.zopyra.com>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “Stupid question on getting branch from yesterday”
  1. Bill LearFeb 14, 2007
  2. Shawn O. PearceFeb 14, 2007
  3. Junio C HamanoFeb 14, 2007
  4. Bill LearFeb 14, 2007
  5. Bill LearFeb 14, 2007
  6. Jeff KingFeb 14, 2007
  7. Junio C HamanoFeb 14, 2007
  8. Linus TorvaldsFeb 14, 2007
  9. Junio C HamanoFeb 14, 2007

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.