tags:

views:

40

answers:

3

I have a folder, which I use "git init", then, I use "git add ." to add all the files in to git. After that, I use a "git commit -m "initial setup" ". Now, I doing something, that I did wrong, I want to back to the status to "git commit -m "initial setup", what can I do? thank you.

I may explain it in this way....

My Files: ABC
---> git add .

My Files: ABC
---> git commit -m "initial setup"

My Files: CDE
--->

I want to roll back to "My Files: ABC"

A: 

The easiest way would be to remove the .git folder that keeps the repository state, then do git init and git add again.

Update: To roll back changes to the working copy files, just do git checkout, which will get the latest committed version from the repository.

Franci Penov
sorry, I may ask it wrong, updated question.
Tattat
+1  A: 

As I understand it: you started out with the folder, which had files A,B,C in it. In this folder you ran the commands

git init
git add .
git commit -m 'initial setup'

Then you made changes to files A,B,C, and now you want to undo those changes? In that case, just run

git checkout *

or I think this works too:

git checkout .

and it will undo any uncommitted changes you've made to the files git is tracking.

David Zaslavsky
User-MacBook:szecau User$ git checkoutM app/views/users/index.html.erbM app/views/users/new.html.erbM config/routes.rbM db/development.sqlite3M db/schema.rbM log/development.logI run this cmd, but I got this, but nothing is roll back.
Tattat
Should be `git checkout *`, I forgot that you have to specify paths.
David Zaslavsky
Sorry, it still don't working, no ideas on that :error: pathspec 'lib' did not match any file(s) known to git.error: pathspec 'tmp' did not match any file(s) known to git.error: pathspec 'vendor' did not match any file(s) known to git.
Tattat
Did you actually check whether the changes on the files were reversed, though? `git` is just warning about paths of files that are not versioned. If it really didn't work, you can explicitly specify the paths of only the files that you want to revert (the usual way to do it), or I _think_ you could run `git reset --hard HEAD`.
David Zaslavsky
yes, I can run git reset --hard HEAD...it display:HEAD is now at 3c331b8 init
Tattat
O...I know what's happen to me, I make a change inside a branch "setting"
Tattat
A: 

Another way:

  1. Get the sha of the commit that you want to restore to (an easy way is to run git log --oneline at the command line which will give you the short sha and the first line of the commit message).
  2. with this sha value run git reset --hard
Abizern