Arjan
Arjan

Reputation: 17054

Build up Git repo from several directories (snapshots)

Following a course in iOS development, I had several assignments. After completing each assignment, I made a copy of the complete project directory. So, now after 4 assignments, I have 4 directories, each with a snapshot of how the project was at that time.

Now I want to start a git repository, and have the "full" history there. I want to start in the first directory, i.e. with the first version of the project, push everything, and then push the differences between the first and the second, etc. But since they're in different directories, I guess I can't simply "git remote add origin" in one after the other and "add --all", "commit", and "push"? Because with "git add --all" I'd push everything all over, not the differences?

Clarification: None of the directories are git repository yet

Upvotes: 1

Views: 77

Answers (1)

VonC
VonC

Reputation: 1323523

If those project directories are not git repos themselves, the easiest way is to use the --work-tree option of the git command:

git init newRepo
cd newRepo

git --work-tree=/path/to/project1 add -A .
git commit -m "Project1"

git --work-tree=/path/to/project2 add -A .
git commit -m "Project2"

The second add command will only add the delta between project1 (already versioned) and project2.

At the end, you would need indeed a git reset --hard, in order to make your working tree (of your actual git repo) in sync with the index.

Note that any git status during the process would not work (in that it would compare your local empty working tree with the index, and would display deletions as a result).

A 'git --work-tree=/path/to/projectx status' would work though.

Upvotes: 2

Related Questions