All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH/RFC] rebase: new convenient option to edit a single commit
Date: Thu, 27 Feb 2014 20:01:18 +0700	[thread overview]
Message-ID: <1393506078-7310-1-git-send-email-pclouds@gmail.com> (raw)

I find myself often do "git rebase -i xxx" and replace one "pick" line
with "edit" to amend just one commit when I see something I don't like
in that commit. This happens often while cleaning up a series. This
automates the "replace" step so it sends me straight to that commit.

"commit --fixup" then "rebase --autosquash" would work too but I still
need to edit todo file to make it stop after squashing so I can test
that commit. So still extra steps.

Or is there a better way to do this?

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 git-rebase--interactive.sh | 17 ++++++++++++++---
 git-rebase.sh              | 10 ++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index d741b04..0988b5c 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -1027,9 +1027,20 @@ fi
 has_action "$todo" ||
 	die_abort "Nothing to do"
 
-cp "$todo" "$todo".backup
-git_sequence_editor "$todo" ||
-	die_abort "Could not execute editor"
+if test -n "$edit_one"
+then
+	edit_one="`git rev-parse --short $edit_one`"
+	sed "1s/pick $edit_one /edit $edit_one /" "$todo" > "$todo.new" ||
+		die_abort "failed to update todo list"
+	grep "^edit $edit_one " "$todo.new" >/dev/null ||
+		die_abort "expected to find 'edit $edit_one' line but did not"
+	mv "$todo.new" "$todo" ||
+		die_abort "failed to update todo list"
+else
+	cp "$todo" "$todo".backup
+	git_sequence_editor "$todo" ||
+		die_abort "Could not execute editor"
+fi
 
 has_action "$todo" ||
 	die_abort "Nothing to do"
diff --git a/git-rebase.sh b/git-rebase.sh
index 1cf8dba..98796cc 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -31,6 +31,7 @@ verify             allow pre-rebase hook to run
 rerere-autoupdate  allow rerere to update index with resolved conflicts
 root!              rebase all reachable commits up to the root(s)
 autosquash         move commits that begin with squash!/fixup! under -i
+1,edit-one!        generate todo list to edit this commit
 committer-date-is-author-date! passed to 'git am'
 ignore-date!       passed to 'git am'
 whitespace=!       passed to 'git apply'
@@ -249,6 +250,10 @@ do
 	-i)
 		interactive_rebase=explicit
 		;;
+	-1)
+		interactive_rebase=explicit
+		edit_one=t
+		;;
 	-k)
 		keep_empty=yes
 		;;
@@ -450,6 +455,11 @@ then
 		;;
 	*)	upstream_name="$1"
 		shift
+		if test -n "$edit_one"
+		then
+			edit_one="$upstream_name"
+			upstream_name="$upstream_name^"
+		fi
 		;;
 	esac
 	upstream=$(peel_committish "${upstream_name}") ||
-- 
1.9.0.66.g14f785a

             reply	other threads:[~2014-02-27 13:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27 13:01 Nguyễn Thái Ngọc Duy [this message]
2014-02-27 13:52 ` [PATCH/RFC] rebase: new convenient option to edit a single commit Matthieu Moy
2014-02-28  6:58 ` Jeff King
2014-02-28  7:34   ` Duy Nguyen
2014-02-28  7:38     ` Jeff King
2014-02-28 17:14   ` Philip Oakley
2014-03-02  2:53 ` [PATCH 0/3] rebase's convenient options Nguyễn Thái Ngọc Duy
2014-03-02  2:53   ` [PATCH 1/3] rev-parse: support OPT_NUMBER_CALLBACK in --parseopt Nguyễn Thái Ngọc Duy
2014-03-04 18:28     ` Junio C Hamano
2014-03-02  2:53   ` [PATCH 2/3] rebase: accept -<number> as another way of saying HEAD~<number> Nguyễn Thái Ngọc Duy
2014-03-02  8:37     ` Eric Sunshine
2014-03-02  8:45       ` Duy Nguyen
2014-03-02  8:53     ` Eric Sunshine
2014-03-02  8:55       ` Eric Sunshine
2014-03-02 15:55         ` Matthieu Moy
2014-03-03  9:16           ` Michael Haggerty
2014-03-03  9:37             ` Matthieu Moy
2014-03-03 10:04               ` Duy Nguyen
2014-03-03 10:11                 ` David Kastrup
2014-03-03 10:12                 ` Matthieu Moy
2014-03-03 10:13               ` Jeff King
2014-03-03 21:48               ` Junio C Hamano
2014-03-03 22:39                 ` Matthieu Moy
2014-03-03 21:44             ` Junio C Hamano
2014-03-02  2:53   ` [PATCH 3/3] rebase: new convenient option to edit a single commit Nguyễn Thái Ngọc Duy
2014-03-02  9:04     ` Eric Sunshine
2014-03-02  9:09       ` Eric Sunshine
2014-03-03 10:10         ` Michael Haggerty
2014-03-03 10:15           ` Duy Nguyen
2014-03-03 10:37             ` David Kastrup
2014-03-03 20:28     ` Eric Sunshine
2014-03-04  2:08       ` Duy Nguyen
2014-03-04  8:59         ` Michael Haggerty
2014-03-04 10:24           ` Duy Nguyen
2014-03-04 13:11             ` Michael Haggerty
2014-03-04 18:37           ` Junio C Hamano
2014-03-09  2:49           ` [PATCH/RFC] rebase: new convenient option to edit/reword/delete " Nguyễn Thái Ngọc Duy
2014-03-09 16:30             ` Matthieu Moy
2014-03-10  8:30             ` Michael Haggerty
2014-03-10  8:41               ` Matthieu Moy

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=1393506078-7310-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.