1

I was working on git and found that the name under my old commit message was wrong. It takes a lot of effort to change it using git reset head~1. I haven't pushed it yet. I tried to use git commit --amend, but when I go to the commit and enter this command, an editing window appears, but I don't know how to save it. Please help.

I checked out the git commit I wanted to change. Then I typed git commit --amend. The editing window came up, so I tried to delete the original git name and save it, but I don't know how to save it.

8
  • 1
    Which terminal are you using? On which OS? Which editor is it? Commented Sep 5, 2024 at 9:17
  • I am using windows 10, so I used cmd. Commented Sep 5, 2024 at 9:19
  • Just do git commit --amend -m 'the message I really want' Commented Sep 5, 2024 at 9:43
  • @eftshift0 It should be changed latest commit. I want to change old commit message. Commented Sep 5, 2024 at 9:46
  • 1
    If with old you mean a commit that is somewhere before the last commit you are working on, then you can do git rebase -i the-commit-i-want-to-modify~ (make sure to include the pigtail), when you get the list of commits to work on, the commit you want to modify should be the first one, change the action from pick to reword, save and exit. Commented Sep 5, 2024 at 9:59

1 Answer 1

2

probably its vim or vi , you just need to enter esc then shift + ; and type 'wq' and hit enter. please try and check the vim tutorial in freecodecamp .

update:

you need to find the commit which you want to update comment

HEAD = hash of the commit

git rebase -i HEAD

it opens interactive mode to modify your commit for eg:

pick 123abc First commit
pick 456def Second commit
reword 789ghi Commit you want to change
pick 101jkl Fourth commit

change pick to reword for commit which you want to change

hit ctrl + x and y and hit enter

now it will open the commit that you want to change

edit your commmit and exit with ctrl + x and y and hit enter

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

4 Comments

Yeah, It seems like save in vim. But it is made new commit. I want only change git message.
ah ok let me update the answer
Changing the commit message changes the commit.
really, i dont think so, i tried changin multiple times the hash remains same

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.