Domanda

I'm looking for a proper solution to remove only-timestamp-changes in the history of my repository .

If you wonder what I'm doing here: I'm trying to build a git repository based on downloaded nightly zip archives of a piece of software where every day all files were timestamped with the date.. but weren't actually changed. In order to keep the actual changes, I want to get rid of these changes.

I have already played with filter-branch to remove sub directories. Has someone an idea how to achieve this?

Some additional points I have:

  1. I know that the change is always in a specific line (if I walk from top to bottom, I could remove a change of one file if only this line was touched?)
  2. The old and new timestamp is -- for one commit -- in all files the same.
  3. The line is globally unique, I'd say it's even timeless unique.

Appending

Question 1: How do I know which files are actually changed?

Okay, I give two examples. The first one contains actually a change, the second one only the stamping.

In my examples, the timestamp is always in line 5. My targets are to remove the one line changed in commit A and to eliminate commit B.

Example Commit A (Before)

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

Example Commit A (After)

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

Example Commit B (Before)

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

Example Commit B (After)

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
È stato utile?

Soluzione

Short version: use git filter-branch --tree-filter with a filter that removes the commit stamp in all files. Something like:

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

Git will handle the rest.

Here’s a way to remove those comments using perl:

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

(this will only work if none of your filenames contain spaces).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top