git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, "J. Bruce Fields" <bfields@citi.umich.edu>
Subject: [PATCH] user-manual: how to replace commits older than most recent
Date: Sun,  4 Mar 2007 16:59:14 -0500	[thread overview]
Message-ID: <11730455602463-git-send-email-bfields@citi.umich.edu> (raw)
In-Reply-To: <11730455592152-git-send-email-bfields@citi.umich.edu>

From: J. Bruce Fields <bfields@citi.umich.edu>

"Modifying" an old commit by checking it out, --amend'ing it, then
rebasing on top of it, is a slightly cumbersome technique, but I've
found it useful frequently enough to make it seem worth documenting.

Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
---
 Documentation/user-manual.txt |   46 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index 33f8a72..907f122 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -1333,6 +1333,7 @@ with the changes to be reverted, then you will be asked to fix
 conflicts manually, just as in the case of <<resolving-a-merge,
 resolving a merge>>.
 
+[[fixing-a-mistake-by-editing-history]]
 Fixing a mistake by editing history
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -1935,6 +1936,51 @@ return mywork to the state it had before you started the rebase:
 $ git rebase --abort
 -------------------------------------------------
 
+Modifying a single commit
+-------------------------
+
+We saw in <<fixing-a-mistake-by-editing-history>> that you can replace the
+most recent commit using
+
+-------------------------------------------------
+$ git commit --amend
+-------------------------------------------------
+
+which will replace the old commit by a new commit incorporating your
+changes, giving you a chance to edit the old commit message first.
+
+You can also use a combination of this and gitlink:git-rebase[1] to edit
+commits further back in your history.  First, tag the problematic commit with
+
+-------------------------------------------------
+$ git tag bad mywork~5
+-------------------------------------------------
+
+(Either gitk or git-log may be useful for finding the commit.)
+
+Then check out a new branch at that commit, edit it, and rebase the rest of
+the series on top of it:
+
+-------------------------------------------------
+$ git checkout -b TMP bad
+$ # make changes here and update the index
+$ git commit --amend
+$ git rebase --onto TMP bad mywork
+-------------------------------------------------
+
+When you're done, you'll be left with mywork checked out, with the top patches
+on mywork reapplied on top of the modified commit you created in TMP.  You can
+then clean up with
+
+-------------------------------------------------
+$ git branch -d TMP
+$ git tag -d bad
+-------------------------------------------------
+
+Note that the immutable nature of git history means that you haven't really
+"modified" existing commits; instead, you have replaced the old commits with
+new commits having new object names.
+
 Reordering or selecting from a patch series
 -------------------------------------------
 
-- 
1.5.0.gb75812-dirty

  reply	other threads:[~2007-03-04 22:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-04 21:59 Documentation (mostly user manual) patches J. Bruce Fields
2007-03-04 21:59 ` [PATCH] Documentation: mention module option to git-cvsimport J. Bruce Fields
2007-03-04 21:59   ` [PATCH] user-manual: reset to ORIG_HEAD not HEAD to undo merge J. Bruce Fields
2007-03-04 21:59     ` [PATCH] user-manual: ensure generated manual references stylesheet J. Bruce Fields
2007-03-04 21:59       ` [PATCH] user-manual: insert earlier of mention content-addressable architecture J. Bruce Fields
2007-03-04 21:59         ` J. Bruce Fields [this message]
2007-03-04 21:59           ` [PATCH] user-manual: more detailed merge discussion J. Bruce Fields
2007-03-04 21:59             ` [PATCH] glossary: Add definitions for dangling and unreachable objects J. Bruce Fields
2007-03-05  0:45               ` Yasushi SHOJI
2007-03-16 12:44       ` [PATCH] user-manual: ensure generated manual references stylesheet Robert Pluim
2007-03-16 14:24         ` J. Bruce Fields
     [not found]           ` <7C0AC446-57CA-480B-A14E-1E861E2FCBA7@silverinsanity.com>
2007-03-16 15:36             ` J. Bruce Fields
     [not found]               ` <7DA766E4-D88F-4248-BD29-1E0B403BF0BE@silverinsanity.com>
2007-03-16 17:02                 ` J. Bruce Fields
2007-03-05  3:14 ` Documentation (mostly user manual) patches Junio C Hamano
2007-03-05 18:38   ` J. Bruce Fields
2007-03-11  4:35   ` J. Bruce Fields
2007-03-11  4:35     ` [PATCH 1/6] glossary: fix overoptimistic automatic linking of defined terms J. Bruce Fields
2007-03-11  4:35       ` [PATCH 2/6] user-manual: fix inconsistent example J. Bruce Fields
2007-03-11  4:35         ` [PATCH 3/6] user-manual: fix inconsistent use of pull and merge J. Bruce Fields
2007-03-11  4:35           ` [PATCH 4/6] user-manual: fix missing colon in git-show example J. Bruce Fields
2007-03-11  4:35             ` [PATCH 5/6] user-manual: fix rendering of history diagrams J. Bruce Fields
2007-03-11  4:35               ` [PATCH 6/6] user-manual: install user manual stylesheet with other web documents J. Bruce Fields
2007-03-11  4:39         ` [PATCH 2/6] user-manual: fix inconsistent example J. Bruce Fields
2007-03-13 19:31           ` Ramsay Jones
2007-03-14 23:19             ` J. Bruce Fields
2007-03-11  5:35     ` Documentation (mostly user manual) patches Junio C Hamano
2007-03-07 20:19 ` Ramsay Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11730455602463-git-send-email-bfields@citi.umich.edu \
    --to=bfields@citi.umich.edu \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).