I initialized a bare repository on my shared drive and cloned it onto my local drive. I make changes locally, add it, commit it, and push it (git push origin master). I do the same thing on another computer and just git pull to get any changes between computers. I am trying to learn how I would revert back to an old "version" of my code in case I needed to.
First I checkout
git checkout "commit #"
then I try to git add -A and git commit -m "msg"
When I git push origin master I get "everything is up to date" and when I git checkout master and try to pull the old changes on the master it doesn't get them. Any idea on how I can get this to work?
Commits are referenced by SHA-1 hashes. You can use these hashes to refer to any commit. For example, you can check out a specific commit with
where
<sha-1 hash>is a valid hash for any commit in your repo. Be careful with this command as any new commits you make do not belong to any branch. If you want to make changes and commit them, you should create a branch first:Change
new-branchto any name that describes the work you are doing.If you want to reset
masterto a previous commit, then you can useThis will keep all changes in your local copy while dropping all of the commits you made. If you want to purge all of the changes as well, use
--hard:Now you will need to force push to your remote:
Be very careful with these commands. If you are working with a team and any of your team members have pulled your previous changes, they will still have a local copy of them. Force pushing to master will cause conflicts with everyone else's local copies and just overall cause headaches for everyone.