Answer the question
In order to leave comments, you need to log in
Git how to change an old commit?
Hello!
In general, immediately to the question. I have a local git repository, I wanted to slightly change the messages of some commits, I executed git checkout hash
or git checkout HEAD~number
later git commit --amend
edited the commit message, when I looked at the logs, the changes were applied, but as soon as I return to the master branch, the changes disappear and old commits with old hashes and messages are displayed.
What is the correct way to make changes to previous commits?
Answer the question
In order to leave comments, you need to log in
You can make a new branch starting from the commit where you need to change the message. Make a commit --amend on the new branch, then cherry-pick the commits that should remain intact, and then retry. In the end, you need to make the new branch the master. But this is pretty much the same as what you do with rebase -i HEAD~ (this is not from the end of the branch, but only from the desired commit).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question