Often, when using git, I will make a mistake when rebooting or merging something that I really did not want. For example, let's say I have three commits that I initially do not want to show in history, and one that I do, for example A-B-C-D, where Dis the commit that I want. Therefore i run
A-B-C-D
D
git rebase -i HEAD~4
and I squash A, Band C. But then, later, I decided that I really wanted to have two commits, because I Awas absolutely not connected with the other three, and the story would make more sense if it were in itself. Now I will do the following:
A
B
C
git reflog | grep 'rebase -i'
which would spit out a list ending
<someHash> HEAD@{<num>}: rebase -i (start): checkout HEAD~4
and then I ran
git checkout HEAD@{<num>+1} git br -D <branchIWasWorkingOn> git checkout -b <branchIWasWorkingOn> git rebase -i HEAD~4
, , pick ing commit A . , , . : , reflog branch deletion?
pick
reflog
branch deletion
- git reset --soft HEAD~1, 4 . . , A-B-C-D, D - , . git reset --soft HEAD~1 A-B-C D . , , A-B-C-E-F.
git reset --soft HEAD~1
A-B-C
A-B-C-E-F
, HEAD. , , git reset --hard HEAD~n, ( , ). git reset --soft HEAD~1. , , , , , .
git reset --hard HEAD~n
, , , , . , , . , , . , , , .
, , , . Git . , , , , . , - .