When you wanna undo what you just did, git can help us to do that. When you made changes by mistake,
1. git status
2. git diff
ex) // all of those text was removed
3. git checkout index.html
git checkout -- index.html
// means stay on the current branch
<Undo stage files>
ex) resources.html
after git add, how to unstage those changes
==> git reset HEAD resources.html
//means.. "Go look at the head pointer. The Head pointer points the last commit, the tip of the current branch which is master of the current branch.
<Referring commits>
It is possible to change the last commit. The most recent commit is the Head points to.
git add resources.html
// adds to staging area
git commit -m "Rearrange the items"
git log
// you can see it is committed there. The top one is the head pointer. (the most recent commit)
git amend commit
<Retrieving old commits>
git log
//take a look at the last commit we have made
git checkout 2909343455a34 -- resources.html
git status
git diff --staged
git status
git reset HEAD resources.html
git checkout -- resources.html
git status
<Reverting a commit>
Complete mirror image of the previous version
git revert da38884729343853842348aa
git status
git log
// changed to the previous version, and current version went to the previous node
<Using reset to undo many commits>
** Powerful but also very Dangerous!!
git reset
// Just rewind whatever there was after that. Always moves the head pointer.
* --soft: moves head pointer to the specified commits. It does not change staging index or working directory. Safe.
* --mixed (default): changes staging index to match repository. Does not change working directory.
* --hard: changes staging index and working directory to match repository.
'Git' 카테고리의 다른 글
| Remove/Change Previous Commit (0) | 2018.11.08 |
|---|---|
| Rebase My Branch on Top of Something (0) | 2018.11.08 |
| How to view the commit log (0) | 2017.06.11 |
| Performing first commit (0) | 2017.06.11 |
| Initializing a repository (0) | 2017.06.11 |