Reference website: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
A long time ago want to learn git use, but find a traditional tutorial to see my heart is broken, give up, yesterday joined Hao elder brother's group, saw this site, did not think it is fine, today small try, feel good ~
1. Install git
Well, my development environment is Windows 7, the download is a domestic mirror on the site, directly installed by default.
Oh, yes.
2. File Time Machine
In summary, there are the following commands:
Create a Directory
$ mkdir learngit
Show current directory path
$ pwd
/Users/michael/learngit //路径
Turn this directory into a repository that git can manage
$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/
Add files to the warehouse
$ git add readme.txt //没有任何显示,说明添加成功
Submit the file added to the warehouse,-m followed by the description of this commit, and svn very much like
$ git commit -m "wrote a readme file"
View warehouse status, show modified files
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
View the contents of a file that has been modified
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
Git is free software.
View commit history shows the commit log from the nearest to the farthest
$ git log
commit 3628164fb26d48395383f8f31179f24e0882e1e0 //git生成的版本号
Author: Michael Liao <[email protected]>
Date: Tue Aug 20 15:11:49 2013 +0800
append GPL //修改日志
Viewing the commit history line shows the commit log from the most recent to the farthest
$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
Fallback the current version to the previous version
$ git reset --hard HEAD^ //HEAD表示当前版本
HEAD is now at ea34578 add distributed
Specify back to a future version
$ git reset --hard 3628164 //3628164是commit id 写前几位就可以啦
HEAD is now at 3628164 append GPL
View command History
$ git reflog
ea34578 [email protected]{0}: reset: moving to HEAD^
3628164 [email protected]{1}: commit: append GPL
ea34578 [email protected]{2}: commit: add distributed
cb926e7 [email protected]{3}: commit (initial): wrote a readme file
Discard changes to the workspace-very important, no--becomes the "switch to another branch" command
$ git checkout -- readme.txt
//readme.txt自修改后还没有被放到暂存区,撤销修改就回到和版本库一模一样的状态
//readme.txt已经添加到暂存区后,又作了修改,撤销修改就回到添加到暂存区后的状态
Undo the modification of the staging area (unstage), put it back in the workspace, and discard the modification of the workspace to use the previous command.
$ git reset HEAD readme.txt
HEAD
when used, indicates the latest version
Unstaged changes after reset:
M readme.txt
Delete a file in the File Manager
$ rm test.txt
To delete the file from the repository
$ git rm test.txt
rm ‘test.txt‘
$ git commit -m "remove test.txt"
[master d17efd8] remove test.txt
1 file changed, 1 deletion(-)
delete mode 100644 test.txt
Recover deleted files to the latest version
$ git checkout -- test.txt
3.github Remote StorageFirst, create SSH KEY
1. Register your GitHub account first.
2. Create SSH Key:
$ ssh-keygen -t rsa -C "[email protected]"
Then return all the way, using the default values.
3, then will show the location of the two SSH key, do not move it cheap hand.
Second, login to GitHub open setting--ssh Key page, click "Add SSH Key", fill in any title, paste the contents of the file in the Key text box id_rsa.pub
, click "Add Key".
Third, add remote warehouse
1. Log on to GitHub and then, in the upper right corner, find the "Create a new Repo" button to create a new warehouse.
2. We run the command under the local warehouse according to GitHub's prompt learngit
$ git remote add origin [email protected]:veronica3101/learngit.git
3. Push all the contents of the local library to the remote library
$ git push -u origin master
Iv. cloning from a remote library
The existing library on GitHub, copy ssh KEY in clone or download
$ git clone [email protected]:veronica3101/gitskills.git
loning into ‘gitskills‘...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
And then it's a success. ~ La La la ~
4. The pit I met
1.
$ git remote add origin [email protected]:michaelliao/learngit.git
$ git push -u origin master
fatal: Could not read from remote repository.
出现这个提示有两种情况:
第一种: 我手贱把私钥和公钥文件夹移动了,移回去就好了。
第二种: 仓库里没有任何文件。添加一个然后add,commit以后就好啦。
2.
$ git remote add origin [email protected]:veronica3101/learngit1.git
fatal: remote origin already exists.
各种捣腾以后,就变成这样啦~
网友说这样解决:
$ git Remote RM origin
亲测有效。
3. 和上面的一起发生的
$ git remote rm origin
error: Could not remove config section ‘remote.origin‘.
恩,有一个亲测有效的解决方法:
Open the config file in. git and delete [remote Origin] This line is OK ~
In addition, there are two warnings:
1.
$ git push -u origin master
The authenticity of host ‘github.com (192.30.252.120)‘ can‘t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
廖雪峰同志说:“这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes
回车即可。”
2.
warning:permanently added ' github.com ' (RSA) to the list of known hosts.
Looking pretty scary, I thought there was something wrong, but Comrade Liaoche told me "
Git will output a warning telling you that you have added GitHub key to a trust list on this machine. This warning will only appear once, and there will be no warning after the operation. ”
No way, so far, I think he's right.
There's another one, haha ~
To know a magical command:
$ SSH-VVV [email protected]
Will come out a lot of debug words, has not yet figured out what to do with, looks good high-end appearance.
NN, I've finished my writing.
Here are three additional instructions, left to my own ~
1, stone Brother a language awakened dream of people, I decided to start learning the front-end wholeheartedly.
2, joined the Pride of the springboard group, opened my new journey.
3, this is a high-quality group, someone outside, heavens beyond heavens.
Git first Experience