Answer the question
In order to leave comments, you need to log in
How to undo the last two commits without losing local changes?
Prehistory: there
was commit_1, it was pushed to github
was commit_2, it was not pushed to github, because there was an error that the large file
was commit_3, in it I deleted this file via git rm dump.sql
, I pushed to github, but it did not go through, because commit_2 still remembers this file
. How can I undo the last two commits without losing local changes?
Answer the question
In order to leave comments, you need to log in
Very simple. Here is one way.
git reset --soft HEAD~2 # отменить два последних коммита
# с опцией --soft состояние проекта в рабочем каталоге не изменится и ничего не потеряешь
# и все локальные изменения после первого коммита автоматически поместятся в индекс
git commit # создать коммит заново.
You can also simply merge these commits through rebase:
git rebase -i HEAD~2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question