Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a copy of each version of a file in a git repository

I want to copy each committed version of InterestingFile.cpp to a directory.

The destination file should have its commit timestamp as filename (like /tmp/AllVersions/1495035445)

The following example works, but requires a helper.sh script. How can I write in one line without helper script?

$ git rebase -i --exec "~/helper.sh ~/InterestingFile.cpp" --preserve-merges 0123ABCD


$ cat ~/helper.sh  
#!/bin/bash
TIMESTAMP=`git show -s --format=%ct HEAD` 
cp $1 /tmp/AllVersions/${TIMESTAMP}


$ ls -1 /tmp/AllVersions  # here are the files finally
1499951860
1500038126
1500040256
1500363092
like image 223
Jonas Stein Avatar asked Jan 31 '26 05:01

Jonas Stein


1 Answers

git rebase -i --exec "cp ~/InterestingFile.cpp /tmp/AllVersions/$(git show -s --format=%ct HEAD)" --preserve-merges 0123ABCD
like image 127
Anubis Avatar answered Feb 01 '26 19:02

Anubis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!