M
M
Michael2015-08-17 13:57:45
git
Michael, 2015-08-17 13:57:45

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 hashor git checkout HEAD~numberlater git commit --amendedited 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

2 answer(s)
N
Nikolai Markov, 2015-08-17
@manameiz

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).

M
Maxim Uglov, 2019-03-29
@Vencendor

https://habr.com/ru/post/201922/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question