Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

reset

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').

like image 488
Benjol Avatar asked Feb 26 '23 13:02

Benjol


1 Answers

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.
like image 106
wilhelmtell Avatar answered Feb 28 '23 07:02

wilhelmtell