Git經常使用命令

Create remote repo

pwd:/Users/zhanglx/workspace/gittest/
git init --bare

Clone repo from remote repo

git clone /Users/zhanglx/workspace/gittest/

Init a local git repo and add a remote

This is equal to "Clone"git

mkdir myrepo
cd myrepo/
git init
git remote add origin /Users/zhanglx/workspace/gittest/

New branch and switch to this branch

git branch test
git checkout test

Type git branch to check which branch you are working on.github

Add, modify, commit, reset and checkout history

Git文件狀態

Git文件的狀態分爲untracked和tracked, untracked文件是指新建的文件,還沒有被git管理起來。數據庫

tracked又分爲三種狀態:緩存

已提交(committed),已修改(modified)和已暫存(staged)。已提交表示文件已被安全地保存在本地數據庫中了;已修改表示修改了某個文件,但沒有提交保存;已暫存表示把已修改的文件放在下次提交時要保存的清單中。安全

Github

git remote show origin 查看相關信息 git push origin master 將commit的代碼,push到github上。 git pull origin master 將github上的代碼,update到本地。ssh

Delete

git delete file 而後commit的,將沒法恢復。 rm file, 能夠經過git checkout -- file進行恢復。 git rm --cached file,只是在緩存中刪除,this

恢復更改的文件 git checkout — //未git add的文件spa

git reset HEAD //已經git add的文件,能夠用這個取消add,而後用上一條命令恢復code

Push master branch of locale repo to remote origin

git push origin masterrem

Pull (if there are some conflicts, git will call git merge automatically)

git pull origin master

建立SSH key

ssh-keygen
生成的SSH key文件保存在中~/.ssh/id_rsa.pub

添加SSH key到github

接着拷貝.ssh/id_rsa.pub文件內的因此內容
打開github賬號管理中的添加SSH key界面的步驟以下:
1. 登陸github
2. 點擊右上方的Accounting settings圖標
3. 選擇 SSH key
4. 點擊 Add SSH key
相關文章
相關標籤/搜索