Iter Ator
Iter Ator

Reputation: 9299

How is it possible restore .git, without changing any files in the project folder?

One of our developers just downloaded our repository from github in a zip (without the .git directory). He made many changes in it, and wants to upload it back.

I would like to solve this situation by restoring the .git folder, but I have no idea how to do it right. I mostly just called git push, pull, commit, and nothing advanced.

I could clone the repository in a separate directory, and copy the .git folder from there to the working directory, but that seems the wrong way to me.

Upvotes: 2

Views: 54

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391396

The procedure is fairly simply, but since you or someone will have to do all the steps your colleague skipped, you or (s)he is not saving time by doing it this way.

So my #1 tip is this: Teach your colleague how to use git properly.

Now, here's how to rescue the situation

  1. Grab a clone of the repository.

    You can use an existing one but you need to be free to check out branches and so on, if necessary make a fresh clone)

  2. If necessary, check out the commit that your colleague downloaded.

    This is important to make sure his/her changes won't remove changes made by others. This might be hard to know, and is one of the reasons why your colleague absolutely should know how to use git to avoid this mess in the future. I say "if necessary", because there might not be new commits in the repository after the download, but if there are, you must check out the right commit.

  3. Create and check out a new branch at this commit.

    We'll be making a new commit with the files from the zip file, and everything becomes much easier if you can have a branch and probably do a pull request as well.

  4. Apply the zip file on top of the working folder.

    It is important to not only overwrite files in the working folder with files from the zip file, but also to make sure any renames, moves, deletes, are applied correctly. If necessary, use a directory comparison tool to make sure you apply all the changes.

    "Pro tip": If your colleague can remember exactly which files were modified, this step becomes a lot easier.

    Quickfix: If the zip file is complete, then you can simply remove all the files in the working folder and unzip the zip file into it afterwards. Git won't know the difference between the "old" files and the "new" files if they didn't change.

  5. Add and commit the changes.
  6. Merge the branch into "whatever", according to your rules and process.

    It is probably a good idea to set up a pull request and ask your colleague to verify that all the changes were applied correctly.

Upvotes: 2

Related Questions