Git底层命令

Git底层命令

一、git hash-object

计算对象 ID 并可选择从文件创建 blob。(Compute object ID and optionally creates a blob from a file)

语法

git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin [--literally]] [--] <file>…​
git hash-object [-t <type>] [-w] --stdin-paths [--no-filters]

使用命名文件的内容(可以在工作树之外)计算具有指定类型的对象的对象 ID 值,并可选择将结果对象写入对象数据库。 将其对象 ID 报告给其标准输出。 未指定 时,默认为“blob”。

使用

## 创建一个文件
echo 'first file content' > file.txt 
## 简单使用
$ git hash-object file.txt
e8ae2c07b4bff941938380c0e634e45e4d7b4cc4
  • -t <type> 指定类型 (default: "blob")

    $ git hash-object -t blob  file.txt
    e8ae2c07b4bff941938380c0e634e45e4d7b4cc4
    
  • -w 实际写入到Git仓库中

    $ git hash-object -w  file.txt
    warning: LF will be replaced by CRLF in file.txt.
    The file will have its original line endings in your working directory
    e8ae2c07b4bff941938380c0e634e45e4d7b4cc4
    ##  前两位会作为目录,所以查找时要去掉
    $ find ./ -name ae2c07b4bff941938380c0e634e45e4d7b4cc4
    ./.git/objects/e8/ae2c07b4bff941938380c0e634e45e4d7b4cc4
    
  • --stdin 从标准输入而不是从文件中读取对象

    $ echo 's content' |git hash-object -w --stdin
    e8c12be28b86b9556979f789ea6275197bc939c8
    
    user@NAME MINGW64 /d/VSCode/testGit (master)
    $ find ./ -name c12be28b86b9556979f789ea6275197bc939c8
    ./.git/objects/e8/c12be28b86b9556979f789ea6275197bc939c8
    
  • --stdin-paths 从标准输入读取文件名,每行一个,而不是从命令行读取

    user@NAME MINGW64 /d/VSCode/testGit (master)
    $ echo 'sec file content' > file2.txt
    $ git hash-object --stdin-paths 
    file.txt
    e8ae2c07b4bff941938380c0e634e45e4d7b4cc4
    file2.txt
    96304fa75f979d003fe01de4a2a29e4eec97dbbe
    
  • --no-filters

  • --literally

二、git-cat-file

为存储库对象提供内容或类型和大小信息(Provide content or type and size information for repository objects)

语法

git cat-file (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | <type> | --textconv | --filters ) [--path=<path>] <object>
git cat-file (--batch[=<format>] | --batch-check[=<format>]) [ --textconv | --filters ] [--follow-symlinks]

在上述两个语法形式中:

  • 在第一种形式中,该命令提供存储库中对象的内容或类型。 类型是必需的,除非 -t 或 -p 用于查找对象类型,或 -s 用于查找对象大小,或使用 --textconv 或 --filters(暗示类型“blob”)。
  • 在第二种形式中,在标准输入上提供了一个对象列表(由换行符分隔),并且每个对象的 SHA-1、类型和大小都打印在标准输出上。 可以使用可选的 参数覆盖输出格式。 如果指定了 --textconv 或 --filters ,则输入应列出对象名称,后跟路径名称,由单个空格分隔,以便可以确定适当的驱动程序。

使用

  • -p /-t / -s 分别用于查看Git库中文件的内容,类型,大小。

    ## 写入内容到Git库中
    $ echo 'cat-file test content' |git hash-object -w --stdin
    d0f11299188c19b6eaceb25190c5fa9a72578289
    
    $ git cat-file -s d0f11299188c19b6eaceb25190c5fa9a72578289 
    22
    
    user@NAME MINGW64 /d/VSCode/testGit (master)
    $ git cat-file -t d0f11299188c19b6eaceb25190c5fa9a72578289
    blob
    
    user@NAME MINGW64 /d/VSCode/testGit (master)
    $ git cat-file -p d0f11299188c19b6eaceb25190c5fa9a72578289
    cat-file test content
    
  • -e 如果 <object> 存在并且是有效对象,则以零状态退出。 如果 <object> 的格式无效且非零,则在 stderr 上发出错误(查看文件是否中Git库中)。

    $ git cat-file -e  d0f11299188c19b6eaceb25190c5fa9a72578289
    ## 即使删除SHA-1的Id后几位也可以识别
    $ git cat-file -e  d0f11299188c19b6eaceb25190c5fa9a7257
    user@NAME MINGW64 /d/VSCode/testGit (master)
    $ git cat-file -e  d299188c19b6eaceb25190c5fa9a7257
    fatal: Not a valid object name d299188c19b6eaceb25190c5fa9a7257
    
  • --filters

    显示由当前工作树中为给定配置的过滤器转换的内容<path>(即涂抹过滤器、行尾转换等)。在这种情况下,<object>必须是<tree-ish>:<path>, 或的形式:<path>

    git cat-file --filters   d0f11299188c19b6eaceb25190c5fa9a7257:dev
    

三、git-update-index

将工作树中的文件内容注册到索引(暂存区)中(Register file contents in the working tree to the index)

语法

git update-index
             [--add] [--remove | --force-remove] [--replace]
             [--refresh] [-q] [--unmerged] [--ignore-missing]
             [(--cacheinfo <mode>,<object>,<file>)…​]
             [--chmod=(+|-)x]
             [--[no-]assume-unchanged]
             [--[no-]skip-worktree]
             [--[no-]ignore-skip-worktree-entries]
             [--[no-]fsmonitor-valid]
             [--ignore-submodules]
             [--[no-]split-index]
             [--[no-|test-|force-]untracked-cache]
             [--[no-]fsmonitor]
             [--really-refresh] [--unresolve] [--again | -g]
             [--info-only] [--index-info]
             [-z] [--stdin] [--index-version <n>]
             [--verbose]
             [--] [<file>…​]

修改索引。 提到的每个文件都会更新到(索引)暂存区中,并且清除任何未合并或需要更新的状态。另请参阅 git-add(1) 以获得对索引执行一些最常见操作的更用户友好的方式。git update-index 处理文件的方式可以使用各种选项进行修改:

使用

  • --add 如果指定的文件尚未在(索引)暂存区中,则将其添加。已存在就忽略

    ## 初始化一个仓库,并新建一个提交
    $ git init 
    Initialized empty Git repository in D:/VSCode/testUpdateIndex/.git/
    user@NAME MINGW64 /d/VSCode/testUpdateIndex (master)
    $ echo 'in commit content' > test1.txt 
    $ git add . && git commit -m 'commit '
    $ git log 
    commit d265d19d9fceb2da3d24b6ff748c000d22573842 (HEAD -> master)
        commit
    ## 查看工作树和(索引)暂存区中的内容
    $ cat test1.txt && echo '----分割线-----'  &&  git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p
    in commit content
    ----分割线-----
    in commit content
    
    ## 在工作树中添加即将添加到(索引)暂存区中的内容
    $ echo 'in index contet' > test1.txt && cat test1.txt 
    in index contet
    ## 使用git update-index 将修改的内容添加到(索引)暂存区中
    $ git update-index --add  test1.txt
    ## 再次修改工作树 ,并查看工作树内容
    $ echo 'in worktree contet' > test1.txt && cat test1.txt  
    in worktree contet
    ## 查看(索引)暂存区中的内容
    $ git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p
    in index contet
    
    
  • --refresh 查看当前索引并通过检查状态信息来检查是否需要合并或更新。

    ## 从上面的例子中现在
    $ git status 
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            modified:   test1.txt
            
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   test1.txt
            
    ##   --refresh 查看状态
    $ git update-index --refresh  
    test1.txt: needs update
    
    
  • --remove 如果指定的文件在(索引)暂存区中但缺失,则将其删除。默认忽略已删除的文件。

    实际 --remove 的作用是把工作树中文件的状态同步到(索引)暂存区中

    ## 先查看当前工作树和(索引)暂存区中的内容
    $ cat test1.txt && echo '----分割线-----'  &&  git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p
    in worktree contet
    ----分割线-----
    in index contet
    
    ## 使用--remove 把文件从(索引)暂存区中删除,发现(索引)暂存区中的内容变为了工作树内容一样,但是文件并没有删除
    $ git update-index  --remove    test1.txt
    $ git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p
    in worktree contet
    
    ## 手动删除工作树目录中的文件,如下:文件已经标记为了删除状态
    $ git status 
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            modified:   test1.txt
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)        
      (use "git restore <file>..." to discard changes in working directory)
            deleted:    test1.txt
    ## 再次执行 --remove  ,发现(索引)暂存区中文件已经没有了 
    $ git update-index  --remove    test1.txt
    $ git ls-files --stage |grep test1.txt  
    ## 最后,实际 --remove 的作用是把工作树中文件的状态同步到(索引)暂存区中
    
  • --force-remove 即使工作目录仍然有这样的文件,也要从(索引)暂存区中删除该文件。

    实际就是把文件从Git库中删除,变为未跟踪(Untracked)状态

    ## 先把仓库的状态恢复 
    $ git reset --hard HEAD 
    HEAD is now at d265d19 commit
    $ echo 'in index contet' > test1.txt 
    $ git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p
    in commit content 
    ## 将文件添加到(索引)暂存区中,此时 --add --remove 效果是一样的
    $ git update-index --remove test1.txt
    $ git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p 
    in index contet
    ## 使用 --force-remove 将文件从索引(暂存区)中删除
    $ git update-index --force-remove test1.txt
    ## 索引(暂存区)中已经找不到文件了
    $ git ls-files --stage |grep test1.txt 
    $ git status 
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            deleted:    test1.txt
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            test1.txt
            
    
  • -q 安静(Quiet)。如果--refresh发现索引需要更新,则默认行为是错误输出。无论如何,此选项使 git update-index 继续。

  • --ignore-submodules 不要尝试更新子模块。只有在--refresh之前传递时才会遵循此选项。

  • --unmerged 如果--refresh 在索引中找到未合并的更改,则默认行为是出错。此选项无论如何都会使git update-index继续。

    user@NAME MINGW64 /d/VSCode/testUpdateIndex (master|MERGING)
    $ git update-index  test1.txt
    $ git ls-files --stage |grep test1.txt |awk '{print$2}' |xargs git cat-file -p 
    <<<<<<< HEAD
    in master content    
    =======
    in dec branch content
    >>>>>>> dev
    ## 看不懂为啥跟想象中不一样,后面再看
    
  • --ignore-missing 在刷新期间忽略丢失的文件

    $ git update-index --refresh --ignore-missing 
    test1.txt: needs update
    
    user@NAME MINGW64 /d/VSCode/testUpdateIndex (master|MERGING)
    $ git update-index --ignore-missing --refresh 
    
  • --cacheinfo <mode>,<object>,<path> / --cacheinfo <mode> <object> <path> 直接将指定的信息插入到索引中。为了向后兼容,您也可以将这三个参数作为三个单独的参数提供,但鼓励新用户使用单参数形式。

    ## 先直接写入一个Blob对象支仓库中
    $ echo 'hash content' |git hash-object -w --stdin
    889e9b0db98e42c2de7026cad5d52cddda979dd9
    ##  将上面的对象添加到索引(暂存区)中
    $ git update-index --add  --cacheinfo 100644 889e9b0db98e42c2de7026cad5d52cddda979dd9 new_file.txt
    ## 查看文件
    $ git ls-files --stage 
    100644 889e9b0db98e42c2de7026cad5d52cddda979dd9 0       new_file.txt
    100644 a797c96ada9d63a93b30ca8ae5d03327da20267f 0       test1.txt
    ## 查看文件内容
    $  git cat-file -p  889e9b0db98e42c2de7026cad5d52cddda979dd9 
    hash content
    ## new_file.txt 文件是直接添加到索引(暂存区)中,在工作树目录中不存在,所以被标记为了deleted
    $ git status 
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   new_file.txt
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)        
      (use "git restore <file>..." to discard changes in working directory)
            deleted:    new_file.txt
    

四、git-write-tree

从当前索引(暂存区)创建树对象(Create a tree object from the current index)。

语法

git write-tree [--missing-ok] [--prefix=<prefix>/]

使用当前索引创建树对象。 新树对象的名称被打印到标准输出。索引必须处于完全合并状态。从概念上讲, git write-tree sync() 将当前索引内容写入一组树文件。 为了与您的目录中的实际内容相匹配,您需要在执行 git write-tree 之前完成 git update-index 阶段。

使用

  • --missing-ok 通常 git write-tree 确保目录引用的对象存在于对象数据库中。 此选项禁用此检查。
  • --prefix=<prefix>/ 写入表示子目录 的树对象。 这可用于为命名子目录中的子项目编写树对象。

五、git-read-tree

将树信息读入索引(Reads tree information into the index)

git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>]
                [-u [--exclude-per-directory=<gitignore>] | -i]]
                [--index-output=<file>] [--no-sparse-checkout]
                (--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])

给出的树信息读入索引,但实际上并不更新它“缓存”的任何文件。 (参见:git-checkout-index(1))

可选地,它可以将树合并到(索引)暂存区中,使用 -m 标志执行快进(即 2 路)合并或 3 路合并。 当与 -m 一起使用时,-u 标志会导致它也使用合并的结果更新工作树中的文件。简单的合并由 git read-tree 本身完成。 当 git read-tree 返回时,只有冲突的路径才会处于未合并状态。

六、git-commit-tree

创建一个新的提交对象(Create a new commit object)

七、git-ls-files

显示有关索引和工作树中文件的信息(Show information about files in the index and the working tree)

语法

git ls-files [-z] [-t] [-v] [-f]
                (--[cached|deleted|others|ignored|stage|unmerged|killed|modified])*
                (-[c|d|o|i|s|u|k|m])*
                [--eol]
                [--deduplicate]
                [-x <pattern>|--exclude=<pattern>]
                [-X <file>|--exclude-from=<file>]
                [--exclude-per-directory=<file>]
                [--exclude-standard]
                [--error-unmatch] [--with-tree=<tree-ish>]
                [--full-name] [--recurse-submodules]
                [--abbrev[=<n>]] [--] [<file>…​]	

这将(索引)暂存区中的文件列表与实际的工作目录列表合并,并显示两者的不同组合。以下一个或多个选项可用于确定显示的文件:

使用

当前的Git仓库状态

$ ls -l 
total 2
-rw-r--r-- 1 user 197121  0 10月 19 17:34 deletefile.txt   
-rw-r--r-- 1 user 197121 19 10月 19 16:35 incommit.txt     
-rw-r--r-- 1 user 197121  6 10月 19 17:35 instage.txt      
-rw-r--r-- 1 user 197121  0 10月 19 16:48 inworkingtree.txt
-rw-r--r-- 1 user 197121  0 10月 19 16:48 notingit.txt 
##  总共有上述5个文件,文件的状态如下: 
$ git status 
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   instage.txt
        new file:   inworkingtree.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        notingit.txt
        
##  手动删除 deletefile.txt 文件,并且在工作树中修改 inworkingtree.txt 内容后
$ git status 
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   instage.txt
        new file:   inworkingtree.txt

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    deletefile.txt
        modified:   inworkingtree.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        notingit.txt

  • -c /--cached 在输出中显示缓存文件(默认选项)

    $ git ls-files -c
    deletefile.txt   
    incommit.txt     
    instage.txt      
    inworkingtree.txt
    
  • -d /--delete 在输出中显示已删除的文件

    $ git ls-files -d
    deletefile.txt
    
  • -m/--modified 在输出中显示修改后的文件

    $ git ls-files -m
    deletefile.txt   
    inworkingtree.txt
    
  • -o/--others 在输出中显示其他(即未跟踪的)文件

$ git ls-files -o 
notingit.txt
  • -i/--ignored 在输出中仅显示忽略的文件。在(索引)暂存区中显示文件时,仅打印与排除模式匹配的文件。显示“其他”文件时,仅显示与排除模式匹配的文件。标准忽略规则不会自动激活,因此至少需要一个-排除*选项。

    $ git ls-files -i --exclude *.txt
    fatal: ls-files -i must be used with either -o or -c
    ## 必须要配合 -o 或者 -c 使用 
    $ git ls-files -c  -i --exclude  *
    $ git ls-files -c  -i --exclude  in*
    $ git ls-files -c  -i --exclude  ins*
    instage.txt
    ## pattern 为 ins*就显示了仓库中的文件 但是 */in* 不行 ,所以不知道这个pattern的规则到底是个啥
    
    $ git ls-files -o  -i --exclude  *
    $ git ls-files -o  -i --exclude  no*
    notingit.txt
    $ git ls-files -o  -i --exclude  n*
    notingit.txt
    ## -o 显示还在Git库中的文件 ,但是pattern 跟上面的好像又不太一样
    ##  所以这个 pattern 后续再研究研究吧
    
  • -s/--stage 在输出中显示(暂存区)分阶段内容的模式位、对象名称和阶段号。

    $ git ls-files --stage 
    100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       deletefile.txt   
    100644 eedc980bc90f6cd4fb23e7df897737b74a1116f8 0       incommit.txt     
    100644 eaf282d73469ca353d18745c2da005df2a44b931 0       instage.txt      
    100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       inworkingtree.txt
    
  • --directory 如果整个目录被归类为“其他”,请仅显示其名称(带有尾随斜杠),而不是其全部内容。

    ##  在仓库中添加两个文件夹 dirs  dirs2 ,然后把dirs添加到仓库中 
    $ git status 
    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   dirs/dirsfile1.txt
            new file:   dirs/dirsfile2.txt
            modified:   instage.txt
            new file:   inworkingtree.txt
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)        
      (use "git restore <file>..." to discard changes in working directory)
            deleted:    deletefile.txt
            modified:   inworkingtree.txt
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)       
            dirs/dirsfile3.txt
            dirs2/
            notingit.txt
            
    ## 显示仓库中的文件夹内容 ,且dirsfile3.txt没有显示,因为不在仓库中
    $ git ls-files   --directory  D:/VSCode/testGit/dirs/
    dirs/dirsfile1.txt
    dirs/dirsfile2.txt
    $ git ls-files   --directory  dirs
    dirs/dirsfile1.txt
    dirs/dirsfile2.txt
    ## -o 显示不在仓库中的文件夹(如果目录中的文件都还在仓库中,只会显示文件夹名称,不会显示里面的文件列表)
    $ git ls-files -o   --directory  dirs 
    dirs/dirsfile3.txt
    $ git ls-files -o   --directory  dirs2
    dirs2/
    
  • --no-empty-directory 不要列出空目录。没有--directory 就没有效果。

    ## 先添加一个空目录
    $ git ls-files  -o  --directory  
    dirs/dirsfile3.txt
    dirs2/
    dirs3/
    notingit.txt
    ##  上面展示了空目录dirs3/  下面的就排除了
    $ git ls-files  -o  --directory  --no-empty-directory  
    dirs/dirsfile3.txt
    dirs2/
    notingit.txt
    
  • -u/--unmerged 在输出中显示未合并的文件(强制--Stage)

  • -k/--killed 显示文件系统上由于文件/目录冲突而需要删除的文件,以便checkout-index 能够成功。

八、git-diff-tree

比较通过两个树对象找到的 blob 的内容和模式

语法

git diff-tree [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty]
              [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base]
              [<common diff options>] <tree-ish> [<tree-ish>] [<path>...]

比较通过两个树对象找到的 blob 的内容和模式。如果只给出了一个 ,则将提交与其父级进行比较(参见下面的 --stdin )。请注意,git diff-tree可以使用封装在提交对象中的树

使用

## 使用一个真实项目的log 
$ git log -n 6 --pretty=oneline
7162219939a21f6a85cf47cefc4894e147149899 【ID1005444】JK-订舱
d47fec895f09a1050de7a75a2c117d689a133146 【ID1005400】
1de15052807a374abc72572a4fdfbaf8effccbb9 Merge branch 'dev' of 
58cf4f727d0c820ef8dd5c6b977f920c6d9945b4 【ID1005400】
ebd7e8d149dcc9a39b19fb5edf1e9c99b5dad1ab 【ID1005397】 JK-录
## 不使用任何参数和一个commit ,它会与其父级进行比较
$ git diff-tree    82643302766d3e37bb7d0b850364d198f09d8ec6
82643302766d3e37bb7d0b850364d198f09d8ec6
:040000 040000 ae9ce5d1a714f9edef91adaea515c1a18c660b21 970d4ce91397fff665273695aa436d7ed5c2c4c6 M      src

## 不使用任何参数和两个commit 
$ git diff-tree    8264330276 5b765a2bf
:040000 040000 970d4ce91397fff665273695aa436d7ed5c2c4c6 388fa266ed8045d5adf800c606fb2097d1c3152c M      src
  • --name-only 仅显示更改文件的名称

  • --name-status 仅显示更改文件的名称和状态。

  • -r 递归到子树中

  • -t 显示树条目本身以及子树(会显示目录)。默认带上 -r

  • --no-commit-id 在适用时输出带有提交 ID 的行。此标志抑制了提交 ID 输出。

    $ git diff-tree  --name-only  8264330276 5b765a2bf
    src
    $ git diff-tree  --name-status 8264330276 5b765a2bf
    M       src
    $ git diff-tree  --name-status --name-only  8264330276 5b765a2bf
    fatal: --name-only, --name-status, --check and -s are mutually exclusive
    ## -t -r 
    $ git diff-tree -t --name-only     8264330276 5b765a2bf
    src
    src/main
    src/main/java
    src/main/java/com
    src/main/java/com/api
    src/main/java/com/api/other
    src/main/java/com/api/other/CloudSchoolSummaryVo.java
    src/main/java/weaver
    src/main/java/weaver/interfaces
    src/main/java/weaver/interfaces/schedule
    src/main/java/weaver/interfaces/schedule/cloudschool
    src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    $ git diff-tree -r --name-only     8264330276 5b765a2bf
    src/main/java/com/api/other/CloudSchoolSummaryVo.java
    src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    ## 
    $ git diff-tree    --no-commit-id -r --name-only  826433027
    src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    $ git diff-tree      -r --name-only  826433027
    82643302766d3e37bb7d0b850364d198f09d8ec6
    src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    
  • --raw 以原始格式生成差异。这是默认设置。

  • --indent-heuristic 启用改变差异块边界的启发式方法,使补丁更易于阅读。这是默认设置。

  • -p /-u /--patch 生成修改(补丁)的对比

  • --patch-with-raw 等同于 -p --raw

  • --minimal 花额外的时间来确保产生尽可能小的差异。

  • --patience 使用“耐心差异”算法生成差异。

  • --histogram 使用“直方图差异”算法生成差异。

    $ git diff-tree --raw --indent-heuristic 826433027  762f92d08
    :040000 040000 970d4ce9139 ae9ce5d1a714f9 M      src
    $ git diff-tree --patch  826433027  762f92d08 
    diff --git a/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java b/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    index a8659941..c2a49381 100644
    --- a/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java        
    +++ b/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java        
    @@ -52,8 +52,7 @@ public class CloudSchoolCronJob extends BaseCronJob implements CronJob {
             internalTrainerDataSynchronization(token);
             /*  从培训记录中读取数据,并校验后将待考核人员数据写入台账 */
             toBeAssessed();
    -        /*  人员带位升级 */
    -        dwUpgrade();
    +
             logger.info("get  data over");
         }
    ## --patch-with-raw  --minimal  --patience --histogram
    $ git diff-tree --patch-with-raw  --minimal  --patience --histogram   826433027  762f92d08
    :100644 100644 a86599416146bc95571c4518186533b59af0099c c2a493817607f666e7ed3fdbf89ce9f8439de6da M      src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    
    diff --git a/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java b/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    index a8659941..c2a49381 100644
    --- a/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    +++ b/src/main/java/weaver/interfaces/schedule/cloudschool/CloudSchoolCronJob.java
    @@ -52,8 +52,7 @@ public class CloudSchoolCronJob extends BaseCronJob implements CronJob {
             internalTrainerDataSynchronization(token);
             /*  从培训记录中读取数据,并校验后将待考核人员数据写入台账 */
             toBeAssessed();
    -        /*  人员带位升级 */
    -        dwUpgrade();
    +
             logger.info("get  data over");
         }
    
  • -c 这个标志改变了合并提交的显示方式(这意味着它只有在给命令一个 , 或 时才有用--stdin)。它同时显示每个父级与合并结果的差异,而不是一次显示父级和结果之间的成对差异(这是该-m选项的作用)。此外,它仅列出从所有父项修改的文件。

  • -cc 这个标志与-c选项类似。它暗示了-c and-p选项

  • --combined-all-paths 此标志导致组合差异(用于合并提交)列出所有父项的文件名。因此,它仅在指定 -c 或 --cc 时有效,并且可能仅在检测到文件名更改时才有用(即,当请求重命名或复制检测时)。

  • --always 即使差异本身为空,也显示提交本身和提交日志消息。

    $ git diff-tree  -r --name-only  --always  1de15052807a37
    1de15052807a374abc72572a4fdfbaf8effccbb9
    
  • --src-prefix=<prefix> 显示给定的源前缀而不是“a/”。

  • --dst-prefix=<prefix> 显示给定的目的地前缀而不是“b/”。

  • --line-prefix=<prefix> 为每一行输出添加一个附加前缀。

  • --no-prefix 不要显示任何源或目标前缀。

    $ git diff-tree  -r  --name-only   --line-prefix='& ' --no-prefix 1de15052807a37  58cf4f727d0c8
    & src/main/java/weaver/interfaces/workflow/action/SupplierClientToSapAction.java   
    & src/main/java/weaver/interfaces/workflow/action/fssc/SRWLTK2FSSCAction.java      
    & src/main/java/weaver/interfaces/workflow/action/hr/HrHiringAction.java
    & src/main/java/weaver/interfaces/workflow/action/hr/JkSupplementAction.java       
    & src/main/java/weaver/interfaces/workflow/action/hr/JobOrganizationOperation.java 
    & src/main/java/weaver/interfaces/workflow/action/hr/ShHrHiringAction.java
    & src/main/java/weaver/interfaces/workflow/action/hr/Shhr03SupplementAction.java   
    & src/main/java/weaver/interfaces/workflow/action/hr/ValidateRecruitmentAction.java
    
posted @ 2023-02-12 20:29  菜阿  阅读(217)  评论(0编辑  收藏  举报