On Mon, Nov 24, 2014 at 6:55 AM, Konstantinos Mavroudakis <
kmavrouda...@gmail.com> wrote:

> I am preparing to move the source code for a project to git. There was no
> other version control in the past. I maintained old versions of file:
> "myfile" with change dates at the end as follows: myfile-d20130629,
> myfile-d20140223 myfile-d20141019 etc. "myfile" is the latest version.
>

​I have done something like this in the past. I did a "git init" to set up
git in the directory. I renamed "myfile" to "myfile-<current date>". ​Then
for each "myfile", in the proper order, I did "rename myfile-???? myfile"
followed by a "git add myfile && git commit -m 'myfile as of <date from
filename>'. You might be able to "fake up" a script to do this sort of
thing for you. But you didn't indicate what OS you're running on, so I
don't know.

On Linux, using BASH as the shell, if __ALL__ of your files are
consistently named something like: <file>-d<date>.<extension>, then a BASH
shell something like the following (not tested!) might work.

tar czf ../disaster.tar.gz . # just in case, in order to restore
set -e #abort if any command fails!
find . -type f |\
egrep '^.*-d[[:digit:]]{8}\..*$' |\
sed -r 's/^.*-d([[:digit:]]{8})\..*$/\1/' |\
sort -u |\
while read date; do
  find . -type f -name "*.-d${date}.*" | while read file;do
        newfile=${file/-d${date}/};
        mv -vn ${file} ${newfile} ;git add ${newfile}
  done
  git commit "files from ${date}"
done
set +e # restore normal processing

​In English the above does the following:
make a tar back just in case something horrible happens
"set -e" tells the shell to stop if any error occurs. I.e. do the least
amount of damage
find all the "regular" files in the directory and all subdirectories
select only files which have a name which "looks right" (egrep command)
use sed to extract the dates from the file names
feed that to sort to order them and remove duplicates
read each unique date
for each date, find all files with that date in the name. rename each file
to remove the date and add to the archive; for each date, do a single
commit with the date in the comment.

I hope this is of some help. I am fairly sure the above BASH script will
work, but no promises. Please be careful!!



> Is there a way (using git or other means) to integrate these old files to
> git under "myfile" name versioning preserving the individual old commits
> e.g (commit d20130629, commit d20140223 commit d20141019)?
>
> Moreover, is it possible to add the correct (past) date in each one of
> these commits?
>
> ​I don't know, but perhaps the --date= on the git commit will do what you
want.​


-- 
The temperature of the aqueous content of an unremittingly ogled
culinary vessel will not achieve 100 degrees on the Celsius scale.

Maranatha! <><
John McKown

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to