git-branchless
git-branchless copied to clipboard
amend: Remove post-amend "git reset"
As a followup to #170, let's see if we can remove the post-amend "git reset" that is currently necessary to clear the index state following an amend from the working copy.
Original context:
git reset
is used to reset the index following the amend. Without this, when you amend something from the working copy, the index retains a "shadow" diff following the amend. The index and working copy contain inverse diffs of each other that get cancelled out by a reset
. It's rather strange (which likely indicates I'm missing something here...)
To repro this, remove the checkout line and run:
$ echo "test" > test.txt
$ git commit -am "test"
$ echo "updated contents" > foo.txt
$ git amend
$ git status
HEAD detached from afdaf9a
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: foo.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: foo.txt
$ git diff
diff --git a/foo.txt b/foo.txt
index 014fd71..1385f26 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-test
+updated contents
$ git diff --cached
diff --git a/foo.txt b/foo.txt
index 1385f26..014fd71 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-updated contents
+test
Note that this doesn't happen if you amend a change that is staged to the index -- only when you amend something unstaged from the working copy.
Originally posted by @bcongdon in https://github.com/arxanas/git-branchless/pull/170#discussion_r744126663