P
P
podvzbzdnul2021-02-19 04:36:03
git
podvzbzdnul, 2021-02-19 04:36:03

How to save file rename after git reset head^?

When I need to switch to another task, on the current branch, I just do git commit -am 1 , then come back, do git reset head^ , and keep going.
The crux of the matter is this - for example, there is a renamed file in a commit, but git reset head^ removes the old file and adds a new one.

example
$ git mv 1.txt 2.txt
$ git status 
        renamed:    1.txt -> 2.txt

$ git commit -am test
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename 1.txt => 2.txt (100%)

$ git reset head^
$ git status
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        2.txt

Apparently, this is by design, is there a way to return the result of git mv after a reset?
I used to use git stash / git stash pop --index , but there was often confusion about stashed changes, so I decided to drop it in favor of git commit.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-02-19
@podvzbzdnul

So maybe you need git reset --soft HEAD^ ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question