-
一定要先測試命令的效果後,再用於工作環境中,以防造成不能彌補的後果!到時候別拿著砍刀來找我
-
所有的命令都在git version 2.7.4(Apple Git-66)下測試透過
-
統一概念:
-
工作區:改動(增刪檔案和內容)
-
暫存區:輸入命令:git add 改動的檔案名,此次改動就放到了 ‘暫存區’
-
本地倉庫(簡稱:本地):輸入命令:git commit 此次修改的描述,此次改動就放到了 ’本地倉庫’,每個 commit,我叫它為一個 ‘版本’。
-
遠端倉庫(簡稱:遠端):輸入命令:git push 遠端倉庫,此次改動就放到了 ‘遠端倉庫’(GitHub 等)
-
commit-id:輸出命令:git log,最上面那行 commit xxxxxx,後面的字串就是 commit-id
-
-
如果喜歡這個專案,歡迎 Star、提交 Pr、反饋問題[3]
git help -g
The common Git guides are:
attributes Defining attributes per path
cli Git command-line interface and conventions
core-tutorial A Git core tutorial for developers
cvs-migration Git for CVS users
diffcore Tweaking diff output
everyday A useful minimum set of commands for Everyday Git
glossary A Git Glossary
hooks Hooks used by Git
ignore Specifies intentionally untracked files to ignore
modules Defining submodule properties
namespaces Git namespaces
repository-layout Git Repository Layout
revisions Specifying revisions and ranges for Git
tutorial A tutorial introduction to Git
tutorial-2 A tutorial introduction to Git: part two
workflows An overview of recommended workflows with Git
'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help
' or 'git help ' to read about a specific subcommand or concept.
git fetch --all && git reset --hard origin/master
git update-ref -d HEAD
git diff
git diff <commit-id> <commit-id>
git diff --cached
git diff HEAD
git checkout -
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
git branch -vv
git branch -u origin/mybranch
git push origin/mybranch -u
git branch -r
git branch -a
git checkout -b <branch-name>
git checkout -b <branch-name> origin/<branch-name>
git branch -d <local-branchname>
git push origin --delete <remote-branchname>
git push origin :<remote-branchname>
git branch -m <new-branch-name>
git tag
git describe --tags --abbrev=0
git tag -ln
git tag <version-number>
$ git tag -a <version-number> -m "v1.0 釋出(描述)" <commit-id>
git push origin <local-version-number>
git push origin --tags
git tag -d <tag-name>
git push origin :refs/tags/<tag-name>
git checkout -b branch_name tag_name
git checkout <file-name>
git checkout .
git rev-list -n 1 HEAD -- #得到 deleting_commit
git checkout ^ -- #回到刪除檔案 deleting_commit 之前的狀態
git revert <commit-id>
git reset <commit-id> #預設就是-mixed引數。
git reset –mixed HEAD^ #回退至上個版本,它將重置HEAD到另外一個commit,並且重置暫存區以便和HEAD相匹配,但是也到此為止。工作區不會被更改。
git reset –soft HEAD~3 #回退至三個版本之前,只回退了commit的資訊,暫存區和工作區與回退之前保持一致。如果還要提交,直接commit即可
git reset –hard <commit-id> #徹底回退到指定commit-id的狀態,暫存區和工作區也會變為指定commit-id版本的內容
git commit --amend
git log
git blame <file-name>
git reflog
git commit --amend --author='Author Name '
git remote set-url origin <URL>
git remote add origin <remote-url>
git remote
git whatchanged --since='2 weeks ago'
git checkout <branch-name> && git cherry-pick <commit-id>
git config --global alias.<handle>
比如:git status 改成 git st,這樣可以簡化命令
git config --global alias.st status
git stash
git stash -u
git stash list
git stash apply <stash@{n}>
git stash pop
git stash clear
git checkout <stash@{n}> -- <file-path>
git ls-files -t
git ls-files --others
git ls-files --others -i --exclude-standard
-
clean 後,刪除的檔案無法找回
-
不會影響 tracked 的檔案的改動,只會刪除 untracked 的檔案
git clean <file-name> -f
git clean <directory-name> -df
git log --pretty=oneline --graph --decorate --all
git bundle create <branch-name>
git clone repo.bundle <repo-dir> -b <branch-name>
git rebase --autostash
git fetch origin pull/<id>/head:<branch-name>
git diff --word-diff
git clean -X -f
git config --local --list(當前目錄)
git config --global --list(全域性)
git status --ignored
git log Branch1 ^Branch2
git log --show-signature
git config --global --unset <entry-name>
git checkout --orphan <branch-name>
git show <branch-name>:<file-name>
git clone -b <branch-name> --single-branch https://github.com/user/repo.git
git update-index --assume-unchanged path/to/file
git update-index --no-assume-unchanged path/to/file
git config core.fileMode false
git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/
git log --all --grep=''
git reset <file-name>
git push -f <remote-name> <branch-name>
-
標題行:必填,描述主要修改型別和內容
-
主題內容:描述為什麼修改,做了什麼樣的修改,以及開發的思路等等
-
頁尾註釋:放 Breaking Changes 或 Closed Issues
-
type:commit 的型別
-
feat:新特性
-
fix:修改問題
-
refactor:程式碼重構
-
docs:檔案修改
-
style:程式碼格式修改,註意不是 css 修改
-
test:測試用例修改
-
chore:其他修改,比如構建流程,依賴管理
-
scope:commit 影響的範圍,比如:route,component,utils,build……
-
subject:commit 的概述
-
body:commit 具體修改內容,可以分為多行
-
footer:一些備註,通常是 BREAKING CHANGE 或修複的 bug 的連結
npm install -g commitizen cz-conventional-changelog
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
-
https://github.com/git-tips/tips
-
http://rogerdudler.github.io/git-guide/index.zh.html
-
https://github.com/521xueweihan/git-tips/issues
-
http://sg552.iteye.com/blog/1300713#bc2367928
-
https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000
-
https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
-
https://github.com/commitizen/cz-cli
朋友會在“發現-看一看”看到你“在看”的內容