Benjol
Benjol

Reputation: 66541

How do I populate my empty working tree from the repository in git?

I must be missing something, because I've read all the doc for reset, revert, etc., but I can't work out how to get the contents of my index into the working tree. (I copied the .git folder from elsewhere and just want to do a 'get latest').

Upvotes: 4

Views: 2363

Answers (3)

Jeff Ferland
Jeff Ferland

Reputation: 18292

git checkout -f HEAD

That will cause all of the files to be forcefully checked out, overwriting what git thinks is currently a deletion. HEAD can also be any reference (branch, commit id, etc).

Upvotes: 1

wilhelmtell
wilhelmtell

Reputation: 58677

git commit -m'for now'
git checkout -f
git reset --soft HEAD~
  • The first step will store the index changes in the repository DAG.
  • The checkout step is necessary here because your repository doesn't have a working tree (i.e. it consists of nothing but the .git/ directory), and so the checkout will arrange for the working tree to reflect HEAD.
  • The last step points the HEAD reference to its parent, thus effectively discarding the last commit. The commit is still in the DAG, pointed at by the reflog should you ever care to look at it, but its not part of your branch's timeline anymore. This step is a soft reset, which means that Git places back the changes of that last commit in the index, and it doesn't change the working tree from how it looked when HEAD pointed at that last commit we committed. The commit is not part of your history but the changes are still there in the working tree and in the stage.

Upvotes: 5

Antoine Pelisse
Antoine Pelisse

Reputation: 13099

Have you tried git clone /path/to/myproject.git ?

Or git clone /path/to/my/copied/.git

Upvotes: 2

Related Questions