In this tutorial you will learn how to undo changes in Git relative to its three-trees architecture.
Code used during this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# Git Undo changes in three-trees # Working directory git status echo "content" >> file-1.txt git status git diff # Discard changes in working directory git checkout -- file-1.txt git status # Staging echo "content" >> file-1.txt git status git add file-1.txt git status # Unstage file git reset HEAD file-1.txt git status # Repository echo "content" >> file-1.txt git status git add file-1.txt git status git commit -m "Add content to file-1.txt" git status git log echo "content" >> file-1.txt git status git add file-1.txt git status # Replace the tip of the current branch by creating a new commit # A new commit id is generated # Works only on the last commit # You can use it only to change the commit message, without doing any change git commit --amend -m "Add content to file-1.txt" # Useful links https://www.liviubalan.com/git-three-trees-architecture |
Useful links:
https://www.liviubalan.com/git-three-trees-architecture