V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jarnanchen
V2EX  ›  程序员

在git里有没有办法只拷贝出commit里修改的文件?

  •  
  •   jarnanchen · 2013-06-07 09:58:41 +08:00 · 3544 次点击
    这是一个创建于 3970 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想要对修改过的文件进行语法以及CodeStyle检查,检查整个repository实在太大了。所以考虑检查以后的每个commit。
    但是要怎么样才能自动把某个commit里的文件拎出来到另外一个地方呢?
    第 1 条附言  ·  2013-06-13 18:00:48 +08:00
    感谢各位的回复,最后的做法是:git show --pretty="format:" --name-only >list.txt
    将变化的文件放到list文件里面;
    然后
    xargs -a ../list.txt cp --parents -t ../B
    把这些文件复制出来了。
    8 条回复    1970-01-01 08:00:00 +08:00
    allenm
        1
    allenm  
       2013-06-07 10:00:17 +08:00
    使用 git hooks 应该可以做到
    jarnanchen
        2
    jarnanchen  
    OP
       2013-06-07 10:07:45 +08:00
    @allenm 可否详细说明?
    NemoAlex
        3
    NemoAlex  
       2013-06-07 10:11:28 +08:00
    找个目录 clone 一份再 checkout 到相应的 commit 即可
    jarnanchen
        4
    jarnanchen  
    OP
       2013-06-07 10:13:44 +08:00
    @NemoAlex Clone之后应该是包含全部的代码的?我只想要这个commit里涉及到的文件
    swulling
        5
    swulling  
       2013-06-07 10:18:37 +08:00   ❤️ 2
    @jarnanchen 组合下命令就行了
    git show HEAD --stat | cat

    然后awk/grep出那些文件cp出来
    johnnyb
        6
    johnnyb  
       2013-06-07 10:19:12 +08:00   ❤️ 2
    git diff HEAD^1 --stat
    risent
        7
    risent  
       2013-06-07 19:37:30 +08:00
    git diff-index --name-only b7718272db12cc431e4267f8c9b23a0198f5b8df
    zhouitpro
        8
    zhouitpro  
       2013-06-13 16:57:12 +08:00
    好吧,我来说两句,使用 cat-file, 4a12bde1403d 这个是commit的哈兮

    git cat-file -p 4a12bde1403d:base.php > base.php
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2595 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.