Git-scm: Git tools - submodules
- Git-scm: Git Submodules man page
- Git Submodules basic explanation 適用場景和使用步驟辫诅,透徹凭戴。
- SitePoint - Understanding and Working with Submodules in Git 引入三方庫的例子,挺好泥栖。
-
Atlassian: Git Submodule workflow tips
Git submodules are a powerful way to leverage git as an external dependency management tool. 適合作為一個外部依賴管理的工具簇宽。 - Git Submodules Pros and Cons 入門,關(guān)于 blog 網(wǎng)站的內(nèi)容(content )吧享、主題(theme )魏割、開發(fā)指南(developer guides)的例子很好。
- 以 mbedtls 依賴為例 講了 Submodules钢颂。
- naging Git projects with submodules and subtrees:submodules 和 subtrees 的區(qū)別钞它。
- The Git submodule: misunderstood beast or remorseless slavering monster?:這篇文章對使用 submodules 以復用 component 的好處說得非常到位。
- Source Control Tools:Android 開發(fā)用到的 Repo、Gerrit 等遭垛。 AOSP: Android Open Source Project.
新建發(fā)行版 create a release
-
Do Git tags only apply to the current branch?: tag 和 branch 標簽和分支什么關(guān)系尼桶?
tag 和 branch 沒任何關(guān)系,tag 只是一個指向一個 commit 的指針锯仪。git show <tag>
列出的就是這個 tag 指向的 commit 的信息泵督。 -
git describe [--tags] <commit>
describes the current branch in terms of the commits since the most recent [possibly lightweight] tag in this branch's history. 列出指定 commit 和 最近 tag 的 基本關(guān)系。
git remote 遠程地址變化
-
git remote set-url origin <新地址>
或者 remove + add庶喜。
git merge --patch
從分支上合并一個文件
- 主支上的一個文件小腊,在分支上變更了(比如解決了一個bug),怎么合并過來久窟?
# 簽出 master秩冈,然后把 amazing_feature_branch 分支的 index.html 并過來。
git checkout master
git checkout --patch amazing_feature_branch index.html
git diff
-
git diff --name-only <Start Commit ID>..<End Commit ID>
: 顯示變更了哪些文件斥扛。這在合并分支時入问,方便查看修改文件列表。
git diff -b -w
: --ignore-space-change --ignore-all-space. 加上這兩個選項稀颁,可以極大的減少那些不重要的變化芬失。 -
What is Git Diff and How Do We Read the Output?
How to read the output from git diff?
詳盡地解釋了git diff
輸出界面上的每一行內(nèi)容的含義,詳實峻村。
git log
- git log 用于查看每個提交的日志(Show commit logs)麸折。從 Viewing the Commit History 開啟了解 git log 的新視角。
- 好的注釋可以讓人一下子就了解本次修改的目的粘昨,比如修改了哪個BUG垢啼,解決了什么問題,實現(xiàn)了什么功能张肾。
- git log --reverse: 從第一個 commit 開始芭析,默認是看最新的 commit。
至于具體修改了哪些文件吞瞪,通過 git log --name-status
即可查知馁启,沒有必要在 commit 的注釋中體現(xiàn)。
-
git log --name-status
發(fā)現(xiàn):M 表示 Modify
R093 表示 Rename 相似度 93%
D 表示刪除
A 表示新加的文件 git log --name-status --oneline
查看提交的注釋和文件列表芍秆;內(nèi)置圖形工具 git gui 和 gitk 當然更方便惯疙。git log --name-status <filename>
查看指定文件的commit記錄(即查看指定文件的變更記錄)。當前目錄下的指定文件妖啥,或者帶上路徑霉颠。
git diff 12a6fa3..7984547 sv_minicurl/src/minicurl.c
: 查看指定文件的修改內(nèi)容。
git diff 12a6fa3 sv_minicurl/src/minicurl.c
: 查看指定文件從指定commit到目前的修改內(nèi)容荆虱。git checkout [commit ID] -- path/to/file
: 將指定文件復原到指定commit的那個版本蒿偎,然后直接 git commit 即可朽们。git rev-parse HEAD
取得當前HEAD的commit值。git log -n 5
只查看前5條诉位。git log --graph
查看所有分支情況骑脱,簡單、清晰圖形標識分支苍糠;git log --pretty=format:"%an %ad %s"
自定義輸出格式:author name, author date, subject叁丧。git log --all --oneline **/<filename>
git log --all --name-status **/*<partoffilename>*
查找哪些提交中包含了指定文件;
--name-status 列出具體的文件目錄岳瞭,**/ 表示任意路徑歹袁;git log --diff-filter=D --summary | grep delete
Get a list of the deleted files and copy the full path of the deleted file.
列出已刪除文件列表;-
git log --stat
:加--reverse
則從最早的開始顯示寝优,加<revision-range>
則只顯示范圍內(nèi)的變更統(tǒng)計。
列出變更的簡略的統(tǒng)計數(shù)據(jù):abbreviated stats for each commit.
git 查看修改歷史或某個文件的修改歷史枫耳?
-
git log -p [a_commit]
: --patch乏矾。只提供一個 commit,則表示列出這個commit及之前的所有改動迁杨。如果想顯示從這個commit到最新改動則a_commit..
钻心。
查看 diff。類似git diff [commit]
-
git log -p <Start Commit ID>..<End Commit ID>
: 顯示改動的內(nèi)容铅协;
-p
參數(shù) Generating patch text with -p捷沸。其中:<Start Commit ID>..<End Commit ID>
指明了范圍 <revision-range>;不指明的話則顯示全部(最初到當下commit狐史,即HEAD)痒给。 -
git log --follow --pretty=oneline <文件名>
使用 git log 命令可列出指定文件的所有改動歷史。由于一個文件的改動是有限次的骏全,所以這里列出每次commit苍柏。查看文件歷史,可以了解文件變遷姜贡。 -
git log -p --follow -- <file>
可以查看該文件整個歷史每次的內(nèi)容變更试吁,包括改名以前的。如果不帶--follow
楼咳,則不會看到改名前的變更歷史熄捍。加上--stat
,則可以看到每次變更的加減行數(shù)母怜。
git blame <file>
可以追溯該文件每行是誰寫的余耽。 git show <commit-id|tag|branch>
- git show 可顯示具體某個 object 的一次 commit、tag 的修改~
- git branch -a --contains <commit>糙申;查找某個commit所在的各個分支宾添,這些分支都包含這個commit船惨。
- git log master..<branch_name> --oneline | tail -1:查看某個分支 branch_name 從 master 分支出來后,提交的第一個commit缕陕,即查看該分支的起源粱锐。查看分支偏離主干情況。
圖形化展示當前分支拓撲:Visualizing branch topology in Git
- 查看各個分支的起源扛邑、分支關(guān)系等怜浅。這個回答 非常好,在配置文件
.gitconfig
建別名 alias lg和hist蔬崩,展示相當清晰恶座,且使用命令方便。
[Alias]
lg = log --graph --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
hist = log --graph --full-history --all --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
-
查看兩個 commit 之間提交的次數(shù):
git log 37efe84..2c7fe25 --pretty=oneline | wc -l
沥阳。
git submodule
-
Using Git Submodules Effectively:可以看看跨琳。
Git submodules are useful when you want to share code that you also need change along with the consumer of that code.
使用 submodules 有額外的復雜性,需要管理好復雜性桐罕。共享代碼和工程代碼可同時修改的情形脉让,適合使用 submodules。
git tag
-
Get the commit hash for a tag: 加 -m 的 tag 叫 annotated tag功炮,他自己有獨立的內(nèi)容存儲區(qū)及SHA1溅潜。她實際指向的那個 commit(underlaying commit)要通過
git rev-parse tag^{}
才能看到背后指向的那個實體 commit。git rev-parse tag
看到的是自己的薪伏。unannotated tag 兩個是一樣的滚澜,只是她背后那個 commit 的一個別名。 -
git tag -m <msg> <tag-name> [<commit>]
打 tag嫁怀。-m <msg> 表示 tag 備注设捐,必須加上,多個表示多個段落塘淑。
對本地當前分支的當前 commit 打標簽挡育,如:git tag -m '修復日期顯示問題' v2.0.609。 -
git tag -n --sort=-taggerdate | head -3
: 最近簽入的 3個 tag(按 taggerdate 倒序)朴爬。git tag sorted in chronological order of the date of the commit pointed to即寒。 -
git ls-remote --tags origin
查看遠程標簽列表; -
git log -1 <tag|commit>
顯示 tag 或者 commit 的信息召噩,其中是數(shù)字 1母赵。
git rev-list -n 1 <tag-name>:列出 tag 指向的 commit;
git log -1 --format=%cs <tag|commit> 顯示 tag 或者 commit 的日期 YYYY-MM-DD具滴。
git tag -l |xargs -n1 git log -1:列出當下每個 tag 對應(yīng)的提交信息凹嘲。 -
git show <tag|commit>
顯示 commit 的信息,文件改動等构韵。 -
git tag -n <tag>
查看標簽注釋周蹭;-n 等同于 -n1趋艘,可以顯示多行注釋,比如 -n3凶朗。 -
git tag -d <tag>
刪除標簽瓷胧; -
git tag -l
查看本地標簽列表 list; -
git log --pretty=oneline <tagname or commit>
查看該 tag(或 commit) 及之前的 每個 commit棚愤。 -
git log --pretty=oneline tagVersion1...tagVersion2
查看 tagVersion2 之前直到 tagVersion1 的所有 commit搓萧。 -
git push origin tag v2.0.609
本地建好標簽后,將標簽推送到遠程宛畦。
git push <remote> tag <tag>
tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>. 冒號前面的是來源 src瘸洛,后面的是目標 dst。
git push <remote> <tag>
git push <remote> <branch> <tag>
git push <remote> <branch> refs/tags/<tag>
Pushing an empty <src> allows you to delete the <dst> ref from the remote repository.
-
git push origin :old_tag
刪除遠程標簽 -
git push origin :old_branch
刪除遠程分支 -
git push <remote> <branch> :refs/tags/<tag>
刪除遠程分支的標簽次和; -
git fetch --prune
和遠程同步反肋,清理本地存儲的遠程分支信息
-p,--prune踏施,After fetching, remove any remote-tracking references that no longer exist on the remote.
如果有人清理了遠程 repo 標簽囚玫,你 git pull 后并不會同步清理本地記錄的那些標簽名;請使用該命令清理那些在遠程并不存在的refs读规; -
遠程倉庫回滾到上一次
$ git reflog
查看日志。
$ git reset <commit>
回滾到<commit>燃少。(這個commit 之后所做的修改都保留在工作區(qū)束亏,即默認 --soft≌缶撸回滾到上次就是git reset HEAD^
)碍遍,撤銷在本地commit的內(nèi)容。
$ git push origin HEAD --force
推送到遠程阳液。慎用怕敬。 - What is the difference between an annotated tag and a lightweight tag?
Tag objects (created with -a, -s, or -u) are called "annotated" tags; they contain a creation date, the tagger name and e-mail, a tagging message, and an optional GnuPG signature. Whereas a "lightweight" tag is simply a name for an object (usually a commit object).
Annotated tags are meant for release while lightweight tags are meant for private or temporary object labels. For this reason, some git commands for naming objects (like git describe) will ignore lightweight tags by default.
參考:Git 分支與整合策略。
- git fetch帘皿;
-
git fetch --prune --prune-tags
(自版本 2.17 支持)
Before fetching, remove any local tags that no longer exist on the remote if --prune is enabled. This option should be used more carefully.
git fetch --prune --prune-tags