Git to use and forget to see more
1. After installation is complete, the final step required settings, input
$ git config --global user.name "qlb6x"
$ git config --global user.email "[email protected]"
2. Find a suitable location, create an empty directory
$ mkdir test
$ cd test
$ pwd
/Users/michael/test
3. this directory into a git repository to manage
$ git init
4. Add files
$ git add readme.txt
5. The documents submitted to the repository
$ git commit -m "write a readme file"
6. Review the results submitted
$ git status
7. There has not been modified
$ git diff
8. Check the version control history
$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0
Author: Michael Liao <[email protected]>
Date: Tue Aug 20 15:11:49 2013 +0800
append GPL
commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao <[email protected]>
Date: Tue Aug 20 14:53:12 2013 +0800
add distributed
commit cb926e7ea50ad11b8f9e909c05226233bf755030
Author: Michael Liao <[email protected]>
Date: Mon Aug 19 17:51:55 2013 +0800
wrote a readme file
$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
9. Return to the previous version
$ git reset --hard HEAD^
$ git reset --hard 3628164
In Git, with HEAD represents the current version, the previous version is the HEAD ^, the previous version is the HEAD ^, can also be written HEAD ^ 100
10. Discard changes to make the workspace file back to the last git commit
or the git add
state of
$ git checkout -- readme.txt
11. Modify the file, and git add
to a staging area, but git commit
before, with the following instructions to modify the temporary area withdrawn back into the work area
$ git reset HEAD readme.txt
summary
Scenario 1: When you change the contents of a file chaotic workspace want direct discard modify the workspace with the command
git checkout -- file
.Scenario 2: When you change not only upset the contents of a file workspace, also added to the staging area, to discard the changes in two steps, the first step command
git reset HEAD file
, returned to the scene 1, the second step by scene 1 operation.Scenario 3: You have submitted improper modifications to the repository, you want to withdraw this submission, a reference version rollback, but the premise is not pushed to the remote repository.
12. Delete the file from the repository, with git rm
deleted, andgit commit
$ git rm test.txt
rm 'test.txt'
$ git commit -m "remove test.txt"
13. Another case is deleting the wrong
$ git checkout -- test.txt
git checkout
In fact, the workspace is a replacement version with the version in the repository, regardless of the workspace is modified or deleted, can be "a key to restore."Command
git rm
is used to delete a file. If a file has been submitted to the repository, so you never have to worry about mistakenly deleted, but be careful, you can only restore files to the latest version, you will lose most recent content changes after you submit .
14. Cloning a local library
$ git clone [email protected]:qlb6x/Qlb6x.github.io
Cloning into 'qlb6x.github.io'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), 7.12 KiB | 0 bytes/s, done.
Checking connectivity... done.
Original: Big Box basic method for Git