git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
zo
V2EX  ›  git

git 有什么办法可以比对任意两次提交中一个作者修改了哪些文件吗?

  •  
  •   zo · Jun 9, 2017 · 4632 views
    This topic created in 3265 days ago, the information mentioned may be changed or developed.

    比如比对当前 HEAD 和上一个版本更新时我修改了哪些文件

    17 replies    2017-06-10 11:19:09 +08:00
    zo
        1
    zo  
    OP
       Jun 9, 2017
    或者可以通过 grep 过滤出来?
    jiangbingo
        2
    jiangbingo  
       Jun 9, 2017
    git reflog 查看 hash id 号
    git diff id1 id2
    cxbig
        3
    cxbig  
       Jun 9, 2017
    具体实现看 git diff 和 git log 文档,这种问题 Google 比较快。
    zo
        4
    zo  
    OP
       Jun 9, 2017
    @jiangbingo 这个方法并不能过滤某一个作者的提交。假设开发团体够大的话,想要找到自己提交的东西也是挺难的
    zo
        5
    zo  
    OP
       Jun 9, 2017
    @cxbig 我找过了,但是我找不到
    cxbig
        6
    cxbig  
       Jun 9, 2017
    @zo 怎么可能。。。
    试试这个:
    git --no-pager log --author=YOUR_NAME | head -10
    blakejia
        7
    blakejia  
       Jun 9, 2017
    我觉得 git blame 应该贴合你需求一点。但是一个命令估计也解决不了。
    blakejia
        8
    blakejia  
       Jun 9, 2017
    应该是 git log 拿到文件列表,和 Hash ID,然后去对应文件找你有动过的那些行,做个列表打印出来。得写个小工具了
    cxbig
        9
    cxbig  
       Jun 9, 2017
    @zo
    参数怎么用说的明明白白啊:
    https://git-scm.com/docs/git-log#git-log---authorltpatterngt
    可以加--branches 过滤分支
    可以加--before 和--after 过滤提交时间

    先用 git log 搜你提交的历史,拿到 hash 再用 git diff 比较版本间文件改动
    zo
        10
    zo  
    OP
       Jun 9, 2017
    @blakejia 我去看看 git blame
    zo
        11
    zo  
    OP
       Jun 9, 2017
    @cxbig git diff 显示的是所有人的更改,时间久了的话,找不到哪些是自己提交的。。。。
    wlsnx
        12
    wlsnx  
       Jun 9, 2017
    git log 有 --stat 可以显示修改了哪些文件,-p 可以看到修改内容
    momocraft
        13
    momocraft  
       Jun 9, 2017
    git show commit1..commit2 --author=你
    zo
        14
    zo  
    OP
       Jun 9, 2017
    @wlsnx 用--name-only 就可以了。这样可以直接拿来用
    SoloCompany
        15
    SoloCompany  
       Jun 10, 2017
    @zo 算是自问自答了吗?结合 #13 就是

    git show commit1..commit2 --author=你 --pretty= --name-only | sort -u
    mingyun
        16
    mingyun  
       Jun 10, 2017
    @SoloCompany 学习了
    jiangbingo
        17
    jiangbingo  
       Jun 10, 2017
    根本需求在于快速查看代码提交者的 commit,那就直接使用 Pcharm 的 version control 吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5488 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 83ms · UTC 01:39 · PVG 09:39 · LAX 18:39 · JFK 21:39
    ♥ Do have faith in what you're doing.