Git:删除只更改时间戳的提交

时间:2013-05-24 18:10:02

标签: git git-filter-branch

我正在寻找一个合适的解决方案来删除我的存储库历史记录中的唯一时间戳更改。

如果你想知道我在这里做什么:我正在尝试建立一个git存储库,它基于一个软件下载的每晚zip存档,每天所有文件都带有日期的时间戳...但实际上并没有改变。为了保持实际的变化,我想摆脱这些变化。

我已经使用filter-branch来删除子目录。有人知道如何实现这个目标吗?

我有一些额外的观点:

  1. 我知道更改总是在一个特定的行中(如果我从上到下走,如果只触及此行,我可以删除一个文件的更改吗?)
  2. 旧的和新的时间戳是 - 对于一次提交 - 在所有文件中都是相同的。
  3. 这条线是全球唯一的,我认为它甚至是永恒的独特。
  4. 附加

    问题1:我如何知道实际更改了哪些文件?

    好的,我举两个例子。第一个实际上包含一个变化,第二个只包含冲压。

    在我的示例中,时间戳总是在第5行。我的目标是删除 commit A 中更改的一行并消除 commit B

    示例提交A(之前)

    a file with a header
    a file with a header
    a file with a header
    /*
    Build date: 2013-24-05 11:01:01 (02129bb861061d1a052c592e2dc6b383)
    */
    other stuff
    other stuff
    something before the change
    other stuff
    

    示例提交A(之后)

    a file with a header
    a file with a header
    a file with a header
    /*
    Build date: 2013-25-05 11:01:01 (57cec4137b614c87cb4e24a3d003a3e0)
    */
    other stuff
    other stuff
    something after the change
    other stuff
    

    示例提交B(之前)

    a file with a header
    a file with a header
    a file with a header
    /*
    Build date: 2013-24-05 11:01:01 (02129bb861061d1a052c592e2dc6b383) 
    */
    other stuff
    other stuff
    something which is not altered
    other stuff
    

    示例提交B(之后)

    a file with a header
    a file with a header
    a file with a header
    /*
    Build date: 2013-25-05 11:01:01 (57cec4137b614c87cb4e24a3d003a3e0)
    */
    other stuff
    other stuff
    something which is not altered
    other stuff
    

1 个答案:

答案 0 :(得分:1)

简短版本:使用git filter-branch --tree-filter和过滤器删除所有文件中的提交标记。类似的东西:

find . -name "*" -print | xargs sed -i 's/**commit-stamp-pattern**//g'

Git会处理剩下的事情。

以下是使用perl删除这些注释的方法:

find . -name "*" -print | xargs perl -i -pe 'undef $/; s!^/\*\nBuild date: \d{4}-.*\n\*/\n!!m'

(只有当你的文件名都没有空格时才会有效。)