0

I am new to using git and I am trying to find out how do I revert my code to the version of code from few months ago. So, I am providing pictures and info to help explain.

Looking at our TeamCity repository like shown below, I see that on Jan 03, 2017 @ 9:59AM, 15 files have changed:

enter image description here

If I expand the Changes column for that date, I can drill further down and I can see that 2 files have changed on December 30th, 2016 @9:53AM as shown below:

enter image description here

What is the command I need to issue in git to:

a) get my local code back in time to the version from December 30, 2016 @ 09:53AM like shown above?

b) once I am done investigating it here, how to update my code back to the current version?

pixel
  • 9,653
  • 16
  • 82
  • 149
  • Possible duplicate of [How to revert Git repository to a previous commit?](http://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit) – mkrieger1 Apr 27 '17 at 19:05

2 Answers2

3

The hexadecimal number between the number of files changed and the date in your last picture is an abbreviation of the commit ID. In your highlighted row, it’s a145dcbc9918.

To switch to this commit, you can run

git checkout a145dcbc9918

The same command, with the branch name of either development or master (depending on how your local repository is configured), will get you back to the top of that branch.

Daniel H
  • 7,223
  • 2
  • 26
  • 41
  • Cool, so I guess I could name the checkout as well? How? And what about my 2nd question (b)? Much appreciated – pixel Apr 27 '17 at 18:49
  • You can use `git tag` to name an old commit (run `git help tag` for the exact options it supports). I answered your part (b) above, right below the command I gave. – Daniel H Apr 27 '17 at 19:09
  • Much appreciated Daniel – pixel Apr 27 '17 at 20:25
1

you can use

git log --since='last month' --pretty=format:'%h,%an,%ar,%s'

then

git checkout Commit_hashcode

you can even give it a date like

git log --since="2017-02-12T16:36:00-07:00"

there is also --before and --after check this advanced tuts:

https://www.atlassian.com/git/tutorials/git-log

ROOT
  • 11,363
  • 5
  • 30
  • 45
  • Thanks but I dont need to look at git log since I should have what I need from the screenshots provided in my question right. So, I guess my question is what is commit_hashcode in your git checkout? Is that the string "a145dcbc9918" in red square in my last screenshot? – pixel Apr 27 '17 at 18:48
  • yes it is, you will need to checkout your repo to that date\hashcode_commit and then create a new branch from where you are standing "in the repo history" to be able to work and commit changes or deploy the new branch to prod. – ROOT Apr 27 '17 at 18:52