commiting multiple folders in chronological order into git

岁酱吖の 提交于 2019-12-02 06:22:58

问题


I have several hundred backups of a web site, one per folder. I want to put them into a git repository, each backup as a version. The changes concern mostly image files and 2 database backups per day. The size is around 25 GB an increasing.
Is there a way to tell git to take one of the folders and commit it into the repository, then take the next folder an commit the changes, until they are all commited? Or do I have to copy each folder into the first folder, commit and continue with next folder?
Identical files are hardlinked between folders.
I would like to commit each backup with it's timestamps, but as far as I understand I can supply that with each commit.
So the main information I was looking for is really about specifying a folder not part of the git repository an committing the changes into the repository.


回答1:


Is there a way to tell git to take one of the folders and commit it into the repository, then take the next folder an commit the changes

There is no a simple automatic way, but there is a semi-automatic way. You have to manipulate GIT_WORK_TREE or option --work-tree. Something like that:

cd first-version
git init
git add .
git commit -m "first-version"
git --work-tree=../second-version add -A
git commit -m "second-version"

and repeat for every directory. If all directories have regular, names you can run a loop:

for version_dir in ../*-version; do
    git --work-tree=$version_dir add -A
    git commit -m "$version_dir"
done

I would like to commit them with their timestamps

git doesn't preserve timestamps of files/directories, only of commits.




回答2:


The answer of @phd is the prefect answer for my question.

However, a git-only solution is slow in this regard, particularly the line

git --work-tree=../second-version add -A

Appearently git doesn't recognize easily that identical files are added to the staging.

So, since am working on a Linux system, I used rsync to synchronize my local copy with each folder.

Additionally I am using git lfs for image files. The problem here is that those files are not automatically moved to the lfs system, so I have to migrate them manually. In a script I execute the following command from within the folder of my local copy:

rsync -a ../backupfolder_[$NUMBER]/* . --delete

git add -A

git commit -m "$cmessage"

git lfs migrate import --include="folder/imagefolder1/**"

git lfs migrate import --include="imagefolder2/**"

git reflog expire --expire-unreachable=now --all

git gc --prune=now



来源:https://stackoverflow.com/questions/49802316/commiting-multiple-folders-in-chronological-order-into-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!