Git Commands
tips:<*> means required,[*] means optional
基本操作
創(chuàng)建倉庫
git init
添加文件
git add <filename>
提交更改
git commit -m '<message>'
查看狀態(tài)
git status
查看修改內(nèi)容
git diff
查看日志
git log
回退到目標(biāo)版本
注:
- HEAD為上一個版本,HEAD^為上上個版本,依此類推
- commit id類似3628164
git reset --hard <version>
撤銷更改
- 緩存區(qū)
git reset HEAD <filename>
- 文件
git checkout -- <filename>
刪除文件
git rm <filename>
遠(yuǎn)程倉庫
添加遠(yuǎn)程倉庫
git remote add origin <*.git>
推送到遠(yuǎn)程倉庫
git push [-u] origin <repository-name>
克隆倉庫
git clone <*.git>
分支
創(chuàng)建分支
git branch <branch-name>
切換分支
git checkout <branch-name>
合并某分支到當(dāng)前分支
git checkout -b <branch-name>
創(chuàng)建+切換分支
git checkout -b <branch-name>
查看分支
git branch -a
刪除分支
git branch -d <branch-name>
強(qiáng)行刪除未合并分支
git branch -D <branch-name>
創(chuàng)建遠(yuǎn)程分支到本地
git checkout -b <branch-name> origin/<branch-name>
刪除遠(yuǎn)程分支
git branch -r -d origin/<branch-name>
git push origin :<branch-name>
建立本地分支和遠(yuǎn)程分支的關(guān)聯(lián)
git branch --set-upstream <branch-name> origin/<branch-name>
臨時儲存工作進(jìn)度
儲存
git stash
查看
git stash list
恢復(fù)
git stash apply [stash@{*}]
刪除
git stash drop [stash@{*}]
恢復(fù)并刪除
git stash pop [stash@{*}]
標(biāo)簽
創(chuàng)建標(biāo)簽
git tab <tag-name> [-m 'comment'] [commit-id]
eg.
git tag v0.9 6224937
刪除標(biāo)簽
git tag -d <tag-name>
推送標(biāo)簽
git push origin <tag-name>
刪除遠(yuǎn)程標(biāo)簽
</br>先刪除本地赖阻,然后再
git push origin :refs/tags/<tag-name>
忽略文件
創(chuàng)建:.gitignore双炕,在里面寫入過濾規(guī)則
*.class
test/
強(qiáng)行添加忽略的文件
git add -f <filename>
被忽略的文件的忽略規(guī)則
git check-ignore -v <filename>
自定義命令
(個人認(rèn)為可以理解為C語言中的宏定義)
git config --global alias.<abbr> 'command'
e.g.
git config --global alias.fuck 'push origin'
git config --global alias.logd "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
不小心push了密碼到github上
BFG Repo-Cleaner
用法:
java -jar bfg.jar --replace-text replacements.txt my-repo.git
replacements.txt 這樣寫:
test@qq.com==>xxxx@qq.com