Git learning journey - version rollback
Part I describes several common commands, create and modify files
Brush up again
to check whether there are changes
$ git status
On branch master
nothing to commit, working tree clean
Well, let's start modifying
First, modify the text
这是第一个文件 two
Remember to save! ! !
Adding buffer warehouse
$ git add file1.txt
At any time dynamic monitoring of git
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: file1.txt
Files changed
Submitted to the local repository
$ git commit -m 'del one add two'
[master 7e77647] del one add two
1 file changed, 1 insertion(+), 1 deletion(-)
Check again
$ git status
On branch master
nothing to commit, working tree clean
The work area is clean.
Here we will learn together and version rollback, the purpose is to when something goes wrong all the efforts will not be wasted.
Many times the changes found in the development process and are not satisfied, want to return before changes in, how do le, salad, a joke (ha ha ha)
Closer to home
You can view all versions of git log
On the code:
$ git log
commit 7e77647749e63f99e9519a2e11220c06d5ff7365 (HEAD -> master)
Author: tiamo19980928 <[email protected]>
Date: Wed Apr 8 13:45:42 2020 +0800
del one add two
commit 1d0e2a29ad71b3eefa11c3c56668bf0ae22ccc1c
Author: tiamo19980928 <[email protected]>
Date: Wed Apr 8 11:38:31 2020 +0800
add one
commit fa1e1cc03a9680e501e28e04a9e8b86eba9b5beb
Author: tiamo19980928 <[email protected]>
Date: Wed Apr 8 11:18:43 2020 +0800
这是第一次提交
It looks a little messy, plus a property
–pretty=oneline
$ git log --pretty=oneline
7e77647749e63f99e9519a2e11220c06d5ff7365 (HEAD -> master) del one add two
1d0e2a29ad71b3eefa11c3c56668bf0ae22ccc1c add one
fa1e1cc03a9680e501e28e04a9e8b86eba9b5beb 这是第一次提交
Front of the bunch is the version number
7e77647 ...
The version number from the most recent to the furthest arrangement
You need to know the version number can only be rolled back
Now we fall back to the previous version
First of all, Git must know which version is the current version, in Git, with HEAD represents the current version, the previous version can be represented on a HEAD ^ expressed HEAD ^^ so but more and more time version, not so may be, for example, the fallback version HEAD ~ 20 20
On the code:
$ git reset --hard head^
HEAD is now at 1d0e2a2 add one
Also -hard not know dim, be sure to write (awkward)
Check to see if fall back to the previous version
$ cat file1.txt
这是第一个文件 one
Successful rollback
git log a look at the repository state
$ git log
commit 1d0e2a29ad71b3eefa11c3c56668bf0ae22ccc1c (HEAD -> master)
Author: tiamo19980928 <[email protected]>
Date: Wed Apr 8 11:38:31 2020 +0800
add one
commit fa1e1cc03a9680e501e28e04a9e8b86eba9b5beb
Author: tiamo19980928 <[email protected]>
Date: Wed Apr 8 11:18:43 2020 +0800
这是第一次提交
Before the discovery of the rollback version has disappeared, if suddenly regret, I think back to the previous version, but can not find Zezheng, do not worry. Go down
just before you back-off window has not closed, turned up to find its version number to
the Code:
$ git reset --hard 7e77647
HEAD is now at 7e77647 del one add two
The version number is very long, but there is no need to write down, I suggest writing seven, in the end I do not know why, read on
We look
$ cat file1.txt
这是第一个文件 two
Success back to the previous version rollback
If you turn off the window after the rollback, do not worry, they git considered very comprehensive, but drops
$ git reflog
7e77647 (HEAD -> master) HEAD@{0}: reset: moving to 7e77647
1d0e2a2 HEAD@{1}: reset: moving to head^
7e77647 (HEAD -> master) HEAD@{2}: commit: del one add two
1d0e2a2 HEAD@{3}: commit: add one
fa1e1cc HEAD@{4}: commit (initial): 这是第一次提交
Here is the reason why I recommend the seven, the computer displays only seven people ... Emmm
By git reflog view the command history, find that a version number can be.