-1

I need the state of my repository at a specific commit/date. I don't want to revert back, because I don't want to loose my changes.

How can I get the repository at a specific commit?

I made a research and perhaps the following would work:

git log
git clone /path/to/repository
git checkout dec5f4de67ff32fd ...

Do I get some side-effects between the cloned and the origin repository? Do I have all commits available in my cloned repository? How can I delete the cloned repository? Simply deleting the folder? I don't want a new branch - I only need the project at a specific commit.

Edit:

Now I tried git checkout xxx. It worked. Then I wanted to get back to my latest changes with git checkout master. I got the following error

error: The following untracked working tree files would be overwritten by checkout:
Project/Resources/image.png
Please move or remove them
before you can switch branches. Aborting

The reason was that I checked out the wrong branch (not master). Now I deleted all files and used the one from a backup. If I now enter git log he only shows me the initial commit ... So I moved out of the folder with the console and back in and now he shows me the latest commits.

So be aware of what you checkout.

testing
  • 19,681
  • 50
  • 236
  • 417
  • 1
    Checkout to previous hash will only reverse the changes on your local files until you will commit anything nothing will change in the repository. I think you need to read the basic git tutorial to understand how git works first... – cerkiewny Apr 22 '15 at 11:22
  • So I only use `git checkout dec5...`? How do I get back my latest commits? Again with `git checkout`? – testing Apr 22 '15 at 11:24
  • yes, git checkout is used to navigate between your states of the branch (state of files at certain points in history). So if you will checkout to something then you will lose your changes. Try to play around with some test repository, apply changes, checkout to the HEAD, see what happens. – cerkiewny Apr 22 '15 at 11:26
  • @tobias_k: Those changes are later commits, which are already pushed. – testing Apr 22 '15 at 11:26
  • Until you commit you won't loose any changes, even if you do commit your reverting commit you can always checkout to previous commit and undo the reverting commit.... The only think that actually deletes commit is git reset --hard. But you shouldn't do it nearly ever :) – cerkiewny Apr 22 '15 at 11:28
  • 1
    see http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit – flafoux Apr 22 '15 at 11:28

1 Answers1

2

You want a copy of your repository as it was before commits? The clone will have all the commits from your original. If you want to get rid of the latest commits in the clone you have to use:

git clone /path/to/repository
git reset --hard dec5f4de67ff32fd ...

if you just checkout the commit then the newer commits are still there in the repository, only the work space will be changed to the previous commit.

More detail: https://stackoverflow.com/a/4114122/4809302

Community
  • 1
  • 1
DBrown2207
  • 179
  • 1
  • 10
  • 1
    Safe default would be to create new branch for it via `git checkout -b old_commit dec5f4de6` instead of `reset --hard` though (as shown in the link you posted). – marbu Apr 22 '15 at 13:20