git命令

作者: zouxiaoyu | 来源:发表于2016-06-25 19:42 被阅读0次

2019-08-02:

很困,睡一觉起来继续折腾如何通过git来获取修改的method。没想到测试了网上一个方法,居然真的可行!OMG。so amazing:

https://drunkenmonkey.at/blog/diffs_with_proper_function_context

节选原文如下(我是要搞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 关于通过使用git diff -W 显示修改行附近的functions的命令,虽然接下来抽取怎么搞不明白,但最起码知道了点东西:

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 其实无法获取,还是要进一步分析:

2016-12-28 search issue和pull requests的open或者closed的数目。这下终于不用在

search issues的时候还把pull requests给放进去了,大大的满足感!!!

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可以产生这段范围commit 的changelog文档

git archive --prefix='XXX' --format=zip > XXXX.zip会将当前代码打包。

git describe sha1将会为该commit产生一个名字描述,名字中包含最近一次的tag包名+sha1信息。如果没有tag,则会失败。

git format-patch会将一个个commit达成一个个xxx.patch包,且按顺序来打,这个可以发给email,然后别人可以用git apply,am或者patch命令来实施该patch。

有时我们不需要clone或者add remote。可以直接git pull url来获取结果。

git apply XXX.patch会丢掉author信息。

git apply --check XXX.patch可以事先测试该patch能否成功实施,如果不能,则会报错,如果能,啥消息也没有。当你真正运行git apply xxx.patch后,它并不帮你产生新的create,只是放在index中,让你自己来commit。。

git cherry-pick sha1不管哪种情况,都会产生新的commit。

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

当命令成功运行没有冲突时会保留author信息(不管改不改msg),反之则没有原来的author信息。author变成了commiter。

2016-07-07

1. git pull 默认会将server上所有的分支与local上的分支进行merge。

且会把local上没有的branch也自动fetch到local且创建一个对应的branch。

如果是git pull master就只是会和master进行merge,其他分支不会去merge。

2. git fetch origin貌似没有git fetch branchXXX特意某个分支貌似。所以会将所有的branch数据fetch下来。但不merge。merge需要自己去merge. 当然如果server上有local上没有的branch,git fetch也取不下来了。

在当前分支下,git merge会merge当前分支和对应的远程分支。如果要merge其他分支,需明确标明。

3. git clone会将所有的分支数据clone下来。

2016-07-06 nju

1. git config --system XXX 全局设置,所有用户有效。配置文件在/etc/gitconfig

    git config --global XXX 单个账户设置,对该账户下的所有git repo有效.                 配置文件在~/.gitconfig下或其他类似名

    git config XXX 单个账户下的单个repo下设置,只对该repo有效,会覆盖前2个。配置文件在repo下的.git/config

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

在配置的时候,你可以直接在配置文件里写,还可以在命令行里编写。如

git config --global core.editor vim

使用git config <key>(eg core.editor)会给出该key的具体配置。

2. 对命令获取使用说明:

git help <verb>如git help commit。可以查看任何一个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 可以看一个sha1 hash值为sha1val object对象的内容

使用git add后,就往objects中加入了一个blob对象 sha1值

2) 然后各种git add git rm等这些操作都是先放到index对象中,index对象随着命令的改变内容而改变。index对象中存放内容,路径,sha值啥的。如果你要写tree对象,是从index中的内容写入tree对象的。。从来index都是随时变化的(git add完一次就更新一次内容),根本不属于.git/objects中的对象,objects对象只有四种:blob,tree,commit,tag。其中blob只是content。tree记录blob,dir等,file name等信息。commit指向tree+parent commit,tag指向commit。

git status 可以看index中的状态,而git ls-files -s会得到index中的内容,eg:

100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0 hello.txt

3) 如果想将此刻的index写入tree。可以用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中的内容,而不是working dir中的内容

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计算sha1值

9) objects 中的pack文件夹下原来会将很相似的文件分组,然后保存一个完整版本+delta版本来存储其他文件

10) git rm XX后XX马上就从working dir中消失了,但要真正有效还要git commit下

git rm XX会从index和working dir中同时删除。如果只是要从index中删除可以使用git rm --cached XX

如果不小心删了找不到。还可以找回来: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来看commit信息

2) git show objVal 用来看object的信息

3) ~是一条线上回溯,而^是几个祖先之间回溯

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 循环往复,可以找到first bad commit。进入bisect start模式后,输入bad和good的最初定位后,bisect每次都会从这个范围内找到中间的那个commti让你判断是good 还是bad,由此往复最后帮助定位the first bad commit。结束后记得git bisect reset回来。。

6)git blame -L 35, init/version.c谁最后修改了这个文件的第35行,哪次commit做的这个修改。。其实就是本质跟踪一个文件的行被什么commit改过,同时提供了commiter和时间呗内容被

2016-06-27

1) git stash会将index和working dir中的修改全部抹去

2) git branch会简单显示分支而git show-branch默认会列出最新到几个分支的第一个共同的commit停止。每个分支前面的+号颜色不同,然后*表示的是当前active的branch。

2016-06-28

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

2)git merge后如果正常merge,则会在系统中各自保存commit,并且会有最终的merge commit。

2016-07-03

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

2)git rebase -i master~3 可以对多个XXX进行commit的顺序调换,用squash将后一个commit与前一个合并等。

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

git stash pop将之前保存的弹出来,恢复现场继续工作。

相关文章

  • Github学习文档-3

    目录 1.Git 的基本的命令git init命令git status命令git add命令git commit命...

  • git实用命令

    git实用命令 1 git init 命令 初始化 git 仓库 repository 2 git add 命令 ...

  • git管理工具

    git分支命令 git提交命令

  • git 多条命令一次执行

    上代码git命令 && git命令

  • git入门

    这里对git init、git add、git commit命令进行一个总结。 $ git init 命令,该命令...

  • GIT 常用命令总结

    GIT 常用命令总结 GIT 初始化命令 命令描述git init初始化本地 git 仓库git config -...

  • Git命令整理

    Git命令 ———————————————— git配置: git基本步骤: git分支管理: 创建分支命令: 切...

  • git 分支

    git 显示所有分支(包含本地和远程)命令: git 删除本地分支命令: git 显示远程分支命令: git 删除...

  • Git命令集合

    Git基础命令 git远程关联 git远程关联移除 git命令简单简介 常用命令集合:git init创建版本库 ...

  • git使用指南

    常用命令 帮助类: git --help:显示git命令帮助信息git help -a:显示所有命令git hel...

网友评论

    本文标题:git命令

    本文链接:https://www.haomeiwen.com/subject/gteadttx.html