Original URL: http://www.liaoxuefeng.com/
1. Create a version library
Go to the directory where Git init
2. Add a version
git add 文件名
git commit -m "版本说明文件"
3.回退
git status
git log
git log --pretty=oneline
git reset --hard HEAD^
git reset --hard <ID>
git reflog
git diff HEAD -- readme.txt
git rm test.txt 删除
git checkout --test.txt 恢复
4. 远程仓库
In the user home directory, see if there is no. ssh directory, if there is, then look at this directory there are no id_rsa and id_rsa.pub these two files, if already have, you can skip to the next step. If not, open the shell (open git Bash under Windows) and create SSH Key:
$ ssh-keygen -t rsa -C "[email protected]"
Log on to GitHub and open the "Account Settings", "SSH Keys" page:
Then, click "Add SSH Key", fill in any title, paste the contents of the file in the Key text box id_rsa.pub :
$ git remote add origin git@github.username/repositoryname.git
$ git push -u origin master 把本地库的所有内容推送到远程库上. 第一次带-u,以后可以不用
$ git clone git@github.com:username/gitname.git 从远程库克隆到本地
GitHub gives more than one address and can also use https://github.com/michaelliao/gitskills.git such an address. In fact, GIT supports a variety of protocols, git:// using SSH by default, but can also use https other protocols.
With the https exception of slow speed, one of the biggest problems is that each push must enter a password, but in some companies that only open HTTP ports, the protocol cannot be used ssh https .
5. Create and Merge Branches
Create dev the branch, and then switch to the dev branch:
$ git checkout -b devSwitched to a new branch ‘dev‘
git checkoutThe command plus -b parameter represents creation and switching, equivalent to the following two commands:
$ git branch dev$ git checkout devSwitched to branch ‘dev‘
Then, use the git branch command to view the current branch:
$ git branch* dev master
$ git merge dev 合并
$ git branch -d dev 删除
GIT encourages the use of branching:
To view branches:git branch
To create a branch:git branch <name>
To switch branches:git checkout <name>
Create + switch Branches:git checkout -b <name>
Merge a branch to the current branch:git merge <name>
To delete a branch:git branch -d <name>
Git Learning Notes