代码之家  ›  专栏  ›  技术社区  ›  tanascius

git更改文件修改时间

  •  4
  • tanascius  · 技术社区  · 15 年前

    GitFaq 我能看懂

    Git将当前时间设置为它修改的每个文件上的时间戳,但只设置那些时间戳。

    但是,我尝试了这个命令序列( 编辑: 添加了完整的命令序列)

    $ git init test && cd test
    Initialized empty Git repository in d:/test/.git/
    
    $ touch filea fileb
    
    $ git add .
    
    $ git commit -m "first commit"
    [master (root-commit) fcaf171] first commit
     0 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 filea
     create mode 100644 fileb
    
    $ ls -l > filea
    
    $ touch fileb -t 200912301000
    
    $ ls -l
    total 1
    -rw-r--r--    1 exxxxxxx Administ      132 Feb 12 18:36 filea
    -rw-r--r--    1 exxxxxxx Administ        0 Dec 30 10:00 fileb
    
    $ git status -a
    warning: LF will be replaced by CRLF in filea
    # On branch master
    warning: LF will be replaced by CRLF in filea
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   filea
    #
    
    $ git checkout .
    
    $ ls -l
    total 0
    -rw-r--r--    1 exxxxxxx Administ        0 Feb 12 18:36 filea
    -rw-r--r--    1 exxxxxxx Administ        0 Feb 12 18:36 fileb
    

    现在我的问题是:为什么Git更改了文件的时间戳 fileb ?我希望时间戳保持不变。

    我的命令有问题吗?
    也许可以做一件像 git checkout . --modified 相反?

    我正在使用 git version 1.6.5.1.1367.gcd48 在MingW32/Windows XP下。

    3 回复  |  直到 12 年前
        1
  •  2
  •   seanhodges    15 年前

    sean@SEAN-PC:~/Desktop/test$ ls -la tests/BusTests.*
    -r--r--r-- 1 sean sean 8 2010-02-11 11:53 tests/BusTests.c
    -r--r--r-- 1 sean sean 1 2010-02-11 11:51 tests/BusTests.h
    
    sean@SEAN-PC:~/Desktop/test$ git status -a
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   tests/BusTests.c
    #
    
    sean@SEAN-PC:~/Desktop/test$ git checkout .
    
    sean@SEAN-PC:~/Desktop/test$ ls -la tests/BusTests.*
    -r--r--r-- 1 sean sean 1 2010-02-11 11:55 tests/BusTests.c
    -r--r--r-- 1 sean sean 1 2010-02-11 11:51 tests/BusTests.h
    

    http://code.google.com/p/msysgit/issues/list

    git checkout -- tests/BusTests.c
    
        2
  •  0
  •   tanascius    15 年前
    git ls-files -m | xargs git co --
    

    git checkout

        3
  •  0
  •   Kipras    14 年前