-2

I know how to

but what I want is to exclude the renamed file from last git commit, but retain anything else (as git mv get into my commit unintentionally).

How can I do that?

(Seems I can only revert everything or not at all...)

3
  • You cannot change a commit. It's unclear from your description what the precise problem is. Commented Feb 15, 2024 at 1:24
  • 1
    A move is just a deletion and a creation, so this is the same as separately reverting each of a deletion and a creation, if that helps. (You can also just move it back and amend the commit.) Commented Feb 15, 2024 at 2:10
  • see: atlassian.com/git/tutorials/rewriting-history Commented Feb 15, 2024 at 3:34

1 Answer 1

0

You can search the internet for "git how can I change my latest commit content", you will find documentation pages such as :


One generic way to "change the latest commit" is to edit files and git add them as you want, then run git commit --amend.

This works for any kind of modifications: the commit will simply contain the new content you git added.

For example:

  • to "undo" a git mv old.txt new.txt:
git mv new.txt old.txt
git commit --amend
  • to still remove old.txt but not add new.txt in the commit:
git rm --cached new.txt  # --cached will make git keep the file on disk
git commit --amend
  • to edit a typo:
# edit file foo.txt ...
git add foo.txt
git commit --amend

etc ...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.