0

I only has one git branch (master), also it is a private repository (only used by myself). How can I easily rollback/redo my working dictionary files like snapshot management?

For example:

  1. I commit 1st time, with only 1.txt in the dictionary
  2. I commit 2nd time, to add 2.txt in the dictionary
  3. I commit 3rd time, to add 3.txt in the dictionary

Now the question is:

  1. what command I should issue for git to recover my working dictionary only include 1.txt file?
  2. After above step 1, what git command I should issue again to restore my working dictionary, let it has 3 files (1.txt, 2.txt, 3.txt) again?

Basically I want to treat it as snapshot management for working dictionary to easily switch between different commit. Is it doable with git?

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
henry
  • 25
  • 3

1 Answers1

0
  1. create a new branch: git branch my_branch

  2. switvh to this branch: git checkout my_branch
    (1+2 in one step: git checkout -b my_branch)

  3. reset the branch to the third-last commit: git reset HEAD^^ --hard
    (the count of '^' determines how many commit you go back)

no you can switch between the states by checking you either 'my_branch' or 'master' respectively.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51
  • Thanks for the feedback. So we still use git branch, right? Without branch, we cannot really switch backward or forward. – henry May 14 '18 at 15:50
  • well, you can checkout certain commits without a branch. But you would need to deal with commit IDs. I strongly suggest to use self explaining branch names or at least *tags*. – Timothy Truckle May 14 '18 at 16:02
  • Thanks for great help! – henry May 14 '18 at 16:15