git的use-commit-times相当于什么? [英] What's the equivalent of use-commit-times for git?

查看:123
本文介绍了git的use-commit-times相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要本地服务器和我的服务器上的文件时间戳保持同步。这是在Subversion中通过在配置中设置use-commit-times = true来完成的,这样每个文件的最后一次修改都是在提交时。

每次我克隆我的仓库,我希望文件的时间戳反映它们在远程仓库中的最后一次更改的时间,而不是当我克隆仓库时。



有没有办法做到这一点与git?

解决方案

我不确定这适用于DVCS(如分布式VCS)
$ b

这次大规模的讨论已​​经发生在 2007(看到这个帖子)



Linus的一些回答并不太热衷于这个想法。以下是一个示例:


对不起。如果你没有看到它是如何错误地将日期戳返回到会使你的源代码树简单地make miscompile 的东西,我不知道你在说什么错误的定义。
它是错误的。

它是STUPID。

而且这是完全无法实现的。







(注意:小改进:结帐后,最新文件的时间戳不再被修改 2.2.2+,2015年1月):git checkout - 如何在转换分支时维护时间戳?。)




长答案是:


我认为如果这种情况很常见,那么只需使用多个存储库就会更好。



使用时间戳不会总体工作。它只是保证你make会以一种非常糟糕的方式感到困惑,并且不会重新编译足够的而不是重新编译太多



Git确实能够以许多不同的方式轻松地检查其他分支事物。

您可以创建一些简单的脚本可以执行以下任何操作(从简单到更具异国情调):


  • 只需创建一个新的回购:

      git克隆旧版新版
    cd新版
    git checkout origin /< branch>

    你就在那里。旧时间戳中的旧时间戳很好,你可以在新的时间戳中工作(并编译),而不会影响旧的时间戳。



    使用标志 -n -l -s改为git clone以基本实现这一点。对于大量文件(例如内核等大型回收),它不会像切换分支一样快,但提供工作树的第二个副本可能非常强大。


  • 如果你想

      git archive  - -format = tar --prefix = new-tree /< branchname> | 
    (cd ..; tar xvf - )

    这真的很快,如果你只需要一个快照。

  • 习惯于 git show ,并且只需查看单个文件。

    这实际上真的很有用。你只要做

    $ g $ show otherbranch:

    放在一个xterm窗口中,然后在另一个窗口中查看当前分支中的同一个文件。特别是,对于可编写脚本的编辑器(例如GNU emacs)来说,这应该是微不足道的,在编辑器中应该可以基本上具有整个直接模式,以便使用它。对于我所知道的,emacs git模式已经提供了类似的东西(我不是emacs用户)

  • 并且在virtual目录的东西,至少有人在为FUSE开发一个git插件,也就是说你可以从虚拟目录中看到所有的分支。




我确信以上任何一种都比用文件时间戳玩游戏更好。



Linus



I need the timestamps of files on my local and on my server to be in sync. This is accomplished with Subversion by setting use-commit-times=true in the config so that the last modified of each file is when it was committed.

Each time I clone my repository, I want the timestamps of files to reflect when they were last changed in the remote repository, not when I cloned the repo.

Is there any way to do this with git?

解决方案

I am not sure this would be appropriate for a DVCS (as in "Distributed" VCS)

The huge discussion had already took place in 2007 (see this thread)

And some of Linus's answer were not too keen on the idea. Here is one sample:

I'm sorry. If you don't see how it's WRONG to seta datestamp back to something that will make a simple "make" miscompile your source tree, I don't know what defintiion of "wrong" you are talking about.
It's WRONG.
It's STUPID.
And it's totally INFEASIBLE to implement.


(Note: small improvement: after a checkout, timestamps of up-to-date files are no longer modified (Git 2.2.2+, January 2015): "git checkout - how can I maintain timestamps when switching branches?".)


The long answer was:

I think you're much better off just using multiple repositories instead, if this is something common.

Messing with timestamps is not going to work in general. It's just going to guarantee you that "make" gets confused in a really bad way, and does not recompile enough instead of recompiling too much.

Git does make it possible to do your "check the other branch out" thing very easily, in many different ways.

You could create some trivial script that does any of the following (ranging from the trivial to the more exotic):

  • just create a new repo:

    git clone old new
    cd new
    git checkout origin/<branch>
    

    and there you are. The old timestamps are fine in your old repo, and you can work (and compile) in the new one, without affectign the old one at all.

    Use the flags "-n -l -s" to "git clone" to basically make this instantaneous. For lots of files (eg big repos like the kernel), it's not going to be as fast as just switching branches, but havign a second copy of the working tree can be quite powerful.

  • do the same thing with just a tar-ball instead, if you want to

    git archive --format=tar --prefix=new-tree/ <branchname> |
            (cd .. ; tar xvf -)
    

    which is really quite fast, if you just want a snapshot.

  • get used to "git show", and just look at individual files.
    This is actually really useful at times. You just do

    git show otherbranch:filename
    

    in one xterm window, and look at the same file in your current branch in another window. In particular, this should be trivial to do with scriptable editors (ie GNU emacs), where it should be possible to basically have a whole "dired mode" for other branches within the editor, using this. For all I know, the emacs git mode already offers something like this (I'm not an emacs user)

  • and in the extreme example of that "virtual directory" thing, there was at least somebody working on a git plugin for FUSE, ie you could literally just have virtual directories showing all your branches.

and I'm sure any of the above are better alternatives than playing games with file timestamps.

Linus

这篇关于git的use-commit-times相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆