Put repository to older version

Hey all.

A friend and I made a repository for a project we’re going to be working on together.
We both use github desktop and are very unexperienced with github. It happens fairly often that our repository suddenly takes a 180 degree turn and changes files we never asked it to, leading to tons of errors that we have no idea how to fix.
So, we decided that it’s best to test around with it, while keeping the stable versions around.
How would you go about making a backup of your repository, so that you can reset it back to an older version?

I don’t mind downloading the entire file, get rid of all the repository files and putting that older file back in. Though I don’t know if that’s the best course of action to take :frowning:

Hello and welcome to the community!

I’m not entirely sure what it is you’re looking for. The part that is most confusing to me is:

The entire reason for software version control of any kind, from the ancient SCCS (released around 1973) to the much more modern git (released in 2005), is that the repository tracks different versions of the source code for you so that you don’t have to make a backup of the repository as a separate activity. This is the one operation that all software version control systems have in common.

If you want to understand better how to use version control software in general, and git in specific, I recommend reading Git from the Bottom Up by @jwiegley. It is a great introduction that I think will shed some light on things and help you understand git better and, by extension, software version control.

I hope that helps!


For completeness sake let me add that you can backup a git repository simply by copying the directory. But yes, that should only be necessary to protect against disk failure, or maybe when messing with history. If you just mess up a file you can retrieve it from history, possibly an old commit if you want to undo a previous change.

For introductory reading I personally like the Git Book (it’s an online thing despite the name, though you can get a print copy if you want).

Hey Lee, thank you a lot for replying.

“I’m not entirely sure what it is you’re looking for. The part that is most confusing to me is:”
Let’s say I have a pretty stable repository. I’m happy with the way it is.
Now, somebody suddenly decides to delete a few files. I try to fix them later on. We both end up with merging conflicts. Whoops.
I decide that it’s best to turn this repository back to its stable ‘version’. Perhaps you got confused by my use of version. With a ‘version’, I mean: A form of the repository in the past. The current version causes a lot of merging conflicts and has a lot of bugs. An older version only contains stable files.

Maybe I have a bad understanding of merge conflicts and commits, but I’m confident that I’ll learn more about it as time goes on. I’ll certainly take “Git from the Bottom Up” in mind!

Hey! Thank you for the reply.

I’ll browse through the Git Book some time.

You say that it’s possible to retrieve an old file from history. While I can access the history of my repository, I do not know how to go about retrieving them. I could copy every line in the code and paste them in a new file, though I think you are talking about something else. Would you mind elaborating further?

You can use git checkout (scroll down for examples) to do the following, and some other things:

  • Switch to another branch: git checkout BRANCH_NAME
  • Switch to a random commit (optionally creating a new branch from there): git checkout -b BRANCH_NAME COMMIT_ID
  • Reset a file to the state it had a a random commit: git checkout BRANCH_NAME -- path/to/file
    If you leave out the branch name this resets the file from the index (simply put: the latest commit on your current branch plus any staged changes).

If you need to change the state of the index (e.g. to discard staged changes) or point your branches at other commits (e.g. do discard commits, careful with that!) you can use git reset. Again, scroll down behind that link for examples.