I am looking for an easy way to rearrange snippets between patches. Say I have some repo with two consecutive commits to it:
git init
echo -e "foo\n\nbar\n\nbaz" > file
git add file
git commit -m 'initial'
sed -i 's/bar/boom/' file
git commit -am 'first'
sed -i 's/boom/qux/' file
sed -i 's/baz/quux/' file
git commit -am 'second'
so my commit history looks like this:
first
--- a/file
+++ b/file
@@ -1,5 +1,5 @@
foo
-bar
+boom
baz
second
--- a/file
+++ b/file
@@ -1,5 +1,5 @@
foo
-boom
+qux
-baz
+quux
but I want to look it like this instead:
first
--- a/file
+++ b/file
@@ -1,5 +1,5 @@
foo
-bar
+boom
quux
second
--- a/file
+++ b/file
@@ -1,5 +1,5 @@
foo
-boom
+qux
-baz
+quux
Is there an easy way to do this, with rebase and various commands with -p
options? I think I could do an interactive rebase, edit the first comment, use git reset -p
to remove the last part of the change, save it as a temporary commit, finish the rebase, then do another interactive rebase to squash the temporary commit into the following one. That takes a lot of thinking and effort though in a real-world situation where I want to rearrange two (or more) big commits and need to carry many snippets in both directions, possibly skipping some intermediate commits. Is there an easier way to do this, without creating temporary commits?