git命令

2019-08-02:

很困,睡一覺(jué)起來(lái)繼續(xù)折騰如何通過(guò)git來(lái)獲取修改的method。沒(méi)想到測(cè)試了網(wǎng)上一個(gè)方法,居然真的可行!OMG。so amazing:

https://drunkenmonkey.at/blog/diffs_with_proper_function_context

節(jié)選原文如下(我是要搞java文件,所以就將下面的php換成java就好了。哈哈哈):

The solution

It turns out Git's diff functionality already has support for creating the right function context information for various file types – it just doesn't know which files correspond to which file type. (It seems not even the standard?.php?extension is recognized by default.)

To remedy this, simply create a file with the following contents:

*.engine?? diff=php

*.inc????? diff=php

*.install? diff=php

*.module?? diff=php

*.php????? diff=php

*.profile? diff=php

*.test???? diff=php

*.theme??? diff=php

Save the file either in?.git/info/attributes?or?.gitattributes?(for just the local project), or (to change this globally) in?$HOME/.config/git/attributes?(or?$XDG_CONFIG_HOME/git/attributes, if that variable is set). That's it – testing again, we now see the proper function context in the diff:

@@ -40,6 +40,7 @@ public function operator_options() {

'<=' => t('Is less than or equal to'),

'=' => t('Is equal to'),

'<>' => t('Is not equal to'),

+????? '!=' => t('Is REALLY not equal to'),

'>=' => t('Is greater than or equal to'),

'>' => t('Is greater than'),

'empty' => t('Is empty'),

Much better, right?

Note:?I haven't yet found out where to put the global attributes file for Windows. If you know, please post a comment and tell me, and I'll include it here.

2019-07-22 關(guān)于通過(guò)使用git diff -W 顯示修改行附近的functions的命令,雖然接下來(lái)抽取怎么搞不明白,但最起碼知道了點(diǎn)東西:

https://stackoverflow.com/questions/16525659/is-there-something-similar-to-diff-show-c-function-in-git-diff?noredirect=1&lq=1

git help diff?shows this option:

-W, --function-context

? ? ?Show the whole surrounding functions of changes.

So, it looks like?git diff -W?should do what you want.

Using git to identify all modified functions in a revision?其實(shí)無(wú)法獲取,還是要進(jìn)一步分析:

2016-12-28 search issue和pull requests的open或者closed的數(shù)目。這下終于不用在

search issues的時(shí)候還把pull requests給放進(jìn)去了,大大的滿(mǎn)足感?。。?/p>

You might also take a look at the search apihttps://developer.github.com/v3/search/#search-issues. Looks like you can filter on type and probably also on closed or not :)

https://api.github.com/search/issues?q=+type:pr+user:StackEx??change&sort=created&??order=asc–

2016-12-26 search github repositories

https://api.github.com/search/repositories?q=language:Java+created:"2014-12-03T12:32:42Z .. 2014-12-03T13:32:42Z"

2016-07-12:

git shortlog XXX...XXXX可以產(chǎn)生這段范圍commit 的changelog文檔

git archive --prefix='XXX' --format=zip > XXXX.zip會(huì)將當(dāng)前代碼打包。

git describe sha1將會(huì)為該commit產(chǎn)生一個(gè)名字描述,名字中包含最近一次的tag包名+sha1信息。如果沒(méi)有tag,則會(huì)失敗。

git format-patch會(huì)將一個(gè)個(gè)commit達(dá)成一個(gè)個(gè)xxx.patch包,且按順序來(lái)打,這個(gè)可以發(fā)給email,然后別人可以用git apply,am或者patch命令來(lái)實(shí)施該patch。

有時(shí)我們不需要clone或者add remote??梢灾苯觛it pull url來(lái)獲取結(jié)果。

git apply XXX.patch會(huì)丟掉author信息。

git apply --check XXX.patch可以事先測(cè)試該patch能否成功實(shí)施,如果不能,則會(huì)報(bào)錯(cuò),如果能,啥消息也沒(méi)有。當(dāng)你真正運(yùn)行g(shù)it apply xxx.patch后,它并不幫你產(chǎn)生新的create,只是放在index中,讓你自己來(lái)commit。。

git cherry-pick sha1不管哪種情況,都會(huì)產(chǎn)生新的commit。

git cherry-pick --edit sha1是可以修改commit msg的。

當(dāng)命令成功運(yùn)行沒(méi)有沖突時(shí)會(huì)保留author信息(不管改不改msg),反之則沒(méi)有原來(lái)的author信息。author變成了commiter。

2016-07-07

1. git pull 默認(rèn)會(huì)將server上所有的分支與local上的分支進(jìn)行merge。

且會(huì)把local上沒(méi)有的branch也自動(dòng)fetch到local且創(chuàng)建一個(gè)對(duì)應(yīng)的branch。

如果是git pull master就只是會(huì)和master進(jìn)行merge,其他分支不會(huì)去merge。

2. git fetch origin貌似沒(méi)有g(shù)it fetch branchXXX特意某個(gè)分支貌似。所以會(huì)將所有的branch數(shù)據(jù)fetch下來(lái)。但不merge。merge需要自己去merge. 當(dāng)然如果server上有l(wèi)ocal上沒(méi)有的branch,git fetch也取不下來(lái)了。

在當(dāng)前分支下,git merge會(huì)merge當(dāng)前分支和對(duì)應(yīng)的遠(yuǎn)程分支。如果要merge其他分支,需明確標(biāo)明。

3. git clone會(huì)將所有的分支數(shù)據(jù)clone下來(lái)。

2016-07-06 nju

1. git config --system XXX 全局設(shè)置,所有用戶(hù)有效。配置文件在/etc/gitconfig

??? git config --global XXX 單個(gè)賬戶(hù)設(shè)置,對(duì)該賬戶(hù)下的所有g(shù)it repo有效.???????????????? 配置文件在~/.gitconfig下或其他類(lèi)似名

??? git config XXX 單個(gè)賬戶(hù)下的單個(gè)repo下設(shè)置,只對(duì)該repo有效,會(huì)覆蓋前2個(gè)。配置文件在repo下的.git/config

使用git config --list可以顯示前面所有的3種配置。

在配置的時(shí)候,你可以直接在配置文件里寫(xiě),還可以在命令行里編寫(xiě)。如

git config --global core.editor vim

使用git config <key>(eg core.editor)會(huì)給出該key的具體配置。

2. 對(duì)命令獲取使用說(shuō)明:

git help <verb>如git help commit??梢圆榭慈魏我粋€(gè)git 命令的幫助文檔。

git <verb> --help如git commit --help

man git-<verb>如man git-commit

3. git commit -a -m 'XXX'? = git add all modified tracked files+ git commit -m 'XXX'

2016年06-25

1) git cat-file -p sha1val 可以看一個(gè)sha1 hash值為sha1val object對(duì)象的內(nèi)容

使用git add后,就往objects中加入了一個(gè)blob對(duì)象 sha1值

2) 然后各種git add git rm等這些操作都是先放到index對(duì)象中,index對(duì)象隨著命令的改變內(nèi)容而改變。index對(duì)象中存放內(nèi)容,路徑,sha值啥的。如果你要寫(xiě)tree對(duì)象,是從index中的內(nèi)容寫(xiě)入tree對(duì)象的。。從來(lái)index都是隨時(shí)變化的(git add完一次就更新一次內(nèi)容),根本不屬于.git/objects中的對(duì)象,objects對(duì)象只有四種:blob,tree,commit,tag。其中blob只是content。tree記錄blob,dir等,file name等信息。commit指向tree+parent commit,tag指向commit。

git status 可以看index中的狀態(tài),而git ls-files -s會(huì)得到index中的內(nèi)容,eg:

100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0 hello.txt

3) 如果想將此刻的index寫(xiě)入tree??梢杂?i>git write-tree

4) git commit = git write-tree + git commit-tree treeval

5) git rev-parse V1.0 ?git rev-parse ab1234 都可以得到完整的40位sha1值

6)working dir-> index -> repository。每次commit提交都是index中的內(nèi)容,而不是working dir中的內(nèi)容

7) git commit filename = git add filename + git commit -m 'XXX' while for rm or move, you must git rm/mv filename, then git commit -m 'XXX'

8) git hash-object m1 可以為m1計(jì)算sha1值

9) objects 中的pack文件夾下原來(lái)會(huì)將很相似的文件分組,然后保存一個(gè)完整版本+delta版本來(lái)存儲(chǔ)其他文件

10) git rm XX后XX馬上就從working dir中消失了,但要真正有效還要git commit下

git rm XX會(huì)從index和working dir中同時(shí)刪除。如果只是要從index中刪除可以使用git rm --cached XX

如果不小心刪了找不到。還可以找回來(lái):git checkout HEAD -- filename

11) git log XX可以看到文件名為XX的歷史。但如果XX是重命名后的,要看其之前所有的,可以用git log --follow XX

2016-06-26

1) ?git log -n : list at most n commits;?git log=git log HEAD; git log cmitVal. 使用git log來(lái)看commit信息

2) git show objVal 用來(lái)看object的信息

3) ~是一條線上回溯,而^是幾個(gè)祖先之間回溯

4) X..Y=^X Y from commit X to Y, includes Y excludes X ? ? ? ? ? ? ? ? ? A...B=in A or B but not both

5) git bisect: find the unwork commit

git bisect start->git bisect bad->git bisect good XX-> git bisect bad 循環(huán)往復(fù),可以找到first bad commit。進(jìn)入bisect start模式后,輸入bad和good的最初定位后,bisect每次都會(huì)從這個(gè)范圍內(nèi)找到中間的那個(gè)commti讓你判斷是good 還是bad,由此往復(fù)最后幫助定位the first bad commit。結(jié)束后記得git bisect reset回來(lái)。。

6)git blame -L 35, init/version.c誰(shuí)最后修改了這個(gè)文件的第35行,哪次commit做的這個(gè)修改。。其實(shí)就是本質(zhì)跟蹤一個(gè)文件的行被什么commit改過(guò),同時(shí)提供了commiter和時(shí)間唄內(nèi)容被

2016-06-27

1) git stash會(huì)將index和working dir中的修改全部抹去

2) git branch會(huì)簡(jiǎn)單顯示分支而git show-branch默認(rèn)會(huì)列出最新到幾個(gè)分支的第一個(gè)共同的commit停止。每個(gè)分支前面的+號(hào)顏色不同,然后*表示的是當(dāng)前active的branch。

2016-06-28

1) git log --graph以圖形的形式展示commit序列

2)git merge后如果正常merge,則會(huì)在系統(tǒng)中各自保存commit,并且會(huì)有最終的merge commit。

2016-07-03

1) git rebase branch1, branch2. 將branch2接在branch1的后面

2)git rebase -i master~3 可以對(duì)多個(gè)XXX進(jìn)行commit的順序調(diào)換,用squash將后一個(gè)commit與前一個(gè)合并等。

3)git stash = git stash save,將你的working dir和index保存

git stash pop將之前保存的彈出來(lái),恢復(fù)現(xiàn)場(chǎng)繼續(xù)工作。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容