mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-05-05 05:02:02 +02:00
shit-happens chapter :P
This commit is contained in:
parent
9109394271
commit
12ea306302
7 changed files with 169 additions and 0 deletions
levels/shit-happens
30
levels/shit-happens/bad-commit
Normal file
30
levels/shit-happens/bad-commit
Normal file
|
@ -0,0 +1,30 @@
|
|||
title = Undo a bad commit
|
||||
cards = reset commit-a
|
||||
|
||||
[description]
|
||||
|
||||
Oh no, we made a bad commit! How can we undo making the commit, and go back to a point where we can try again?
|
||||
|
||||
The answer is using `git reset [commit]`, which does two things:
|
||||
|
||||
- It resets the current branch ref to the commit you specify.
|
||||
- And it resets the index to that commit.
|
||||
|
||||
It does not change your working directory in any way, which means that after that, you can try making the commit you want again.
|
||||
|
||||
[setup]
|
||||
|
||||
echo "1 2 3 4" > numbers
|
||||
git add .
|
||||
git commit -m "Initial commit"
|
||||
echo "1 2 3 4 5 6 7 8 9 11" > numbers
|
||||
git commit -am "More numberrrrrs"
|
||||
|
||||
[win]
|
||||
|
||||
# In the last main commit, the numbers file contains the numbers from 1 to 10.
|
||||
test "$(git show main:numbers)" = "1 2 3 4 5 6 7 8 9 10"
|
||||
# The commit message of that commit is "More numbers".
|
||||
git log -1 --oneline | grep "More numbers"
|
||||
# The commit with the typo is not part of the main branch anymore.
|
||||
git log --oneline | grep -v "rrrrr"
|
Loading…
Add table
Add a link
Reference in a new issue