I'm cloning a Git repository by copying the ".git" directory. If I run "git checkout" in that directory it gets me the contents of HEAD. How do I get the staged changes from the original repository? Are they not stored in ".git" and if so is the only way to copy the source files then?
Asked
Active
Viewed 347 times
2
-
I believe this may be what you're looking for: [How do you discard unstaged changes in git?](http://stackoverflow.com/q/52704/1157054) – Ajedi32 Jul 30 '13 at 20:01
-
Not exactly - that would be simply "git clean -df". I could copy the repository with all checked out files and then run that command but that would be slow. It's a waste to copy a bunch of files that I'm going to delete immediately afterwards with a clean command so I'm doing a bare clone and trying to restore the files which were added to it instead. – dromodel Jul 30 '13 at 20:03
-
1@barlor123 That's not what the answers to that question say. `git checkout -- .` should do what you're asking. – Ajedi32 Jul 30 '13 at 20:05
-
Ok I figured it out. You're correct about git checkout. The problem was in my Git wrapper to implement sparse checkout, which reads from HEAD. I'll delete the question. – dromodel Jul 30 '13 at 20:10
1 Answers
3
If you run git status
you should see that the staged changes are still in the index. If that works, go ahead and run:
git checkout -- .
That should reset the the current working directory to match what you have staged.
For more information, see "How do I discard unstaged changes in Git?".
-
2@VladLyga It doesn't sound like he cloned it though, he said he copied the `.git` directory. – Ajedi32 Jul 30 '13 at 20:11
-
Yes, your are right. If he just copies it then your answer is 100% correct and the staged changes should still be. – Vlad Lyga Jul 30 '13 at 20:22