0

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 
4
  • You'll need to explain some more things before I can understand how to approach solving this problem. If all files are timestamped, regardless of whether they've actually changed, how do you know which files actually have changes? Commented May 25, 2013 at 2:15
  • I've updated the question with an example. Commented May 25, 2013 at 9:09
  • do you want to remove those lines or just replace them with something else? Commented May 26, 2013 at 11:30
  • To be honest, I don't care. The final result should not be include these changes. Option 1) remove all lines which look like X, or option 2) replace all lines which look like X with Y (Y is something static). Both okay. Commented May 26, 2013 at 15:24

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, sed is cool. I do not get it right to work, but anyway: sed is cool enough.
I've added my solution and marked this is the final answer, thank you! Perl was a better solution than sed, indeed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.