git checkout - how can I maintain timestamps when switching branches?

前端 未结 3 1738
一个人的身影
一个人的身影 2021-01-02 03:21

I often switch back and forth between branches. I have a script which pushes the contents of the checkout to a \'running\' environment where I can see the code run and test

3条回答
  •  一个人的身影
    2021-01-02 03:44

    The situation (regarding git checkout and timestamps) should be better with Git 2.2.2+ (January 2015).

    The timestamp should not move anymore for files which are already up-to-date when doing a git checkout.

    See commit c5326bd by Jeff King (peff):

    checkout $tree: do not throw away unchanged index entries

    When we "git checkout $tree", we:

    • pull paths from $tree into the index, and then
    • check the resulting entries out to the worktree.

    Our method for the first step is rather heavy-handed, though; it clobbers the entire existing index entry, even if the content is the same.
    This means we lose our stat information, leading checkout_entry to later rewrite the entire file with identical content.

    Instead, let's see if we have the identical entry already in the index, in which case we leave it in place. That lets checkout_entry do the right thing.
    Our tests cover two interesting cases:

    1. We make sure that a file which has no changes is not rewritten.
    2. We make sure that we do update a file that is unchanged in the index (versus $tree), but has working tree changes.
      We keep the old index entry, and checkout_entry is able to realize that our stat information is out of date.

提交回复
热议问题