4

I have three zipped folders named [1,2,3] each contains the same project 1 being the earliest and 3 being the most current. I am looking for a way to merge all of these into 3 git commits and the 3 most commit be the folders contents.

I suppose I can do the following:

  1. Unzip 1.
  2. Take the contents from 1 place it into a new folder.
  3. git init
  4. git add -A
  5. git commit -m "first commit
  6. Unzip 2
  7. replace the contents from the new folder with contents from 2
  8. git add -A
  9. git commit -m "second commit
  10. Unzip 2
  11. replace the contents from the new folder with contents from 3
  12. git add -A
  13. git commit -m "third commit

Could anyone tell me if this is the best way to do this?

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424

4 Answers4

5

Unzip your three zip file in three different directories.

Initialize a git repo in a fourth directory.

Then take advantage of the --work-tree option, which allows you to execute a git command from a git repo, but with a content located outside of said git repo:

cd /your/git/repo
git add --work-tree=/path/to/zip1 -A .
git commit -m "Add v1"
git add --work-tree=/path/to/zip2 -A .
git commit -m "Add v1"
git add --work-tree=/path/to/zip3 -A .
git commit -m "Add v3"

In other words, you can add different contents without moving from your git directory!

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
4

Here's how I would approach this

Get Version 1 commited

mkdir MyProj
cd MyProj
git init
# unzip version1 into MyProj
git add -A
git commit -m "Version 1"

Get Version 2 committed

# delete everything but the .git directory in MyProject
# unzip version2 into MyProj
git add -A 
git commit -m "Version 2"

Get Version 3 committed

Repeat the above for version3 of the zip file.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
2

Each time you run git init, you're creating an empty repository.

If there are only three folders and you're only doing it once, then this will work (if you omit git init). Just make sure not to erase the .git folder.

You could even unzip the three folders and move the .git folder to each in succession and commit in each separate folder, with the final folder being the start of your new repository.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
0

Yes. Just make sure to fully replace the contents, and catch all added and removed files.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173