Setting your branch to exactly match the remote branch can be done in two steps:git
git fetch origin git reset --hard origin/master ##将会保持到和远程库中版本一致
注意该命令须要提早保存copy 出来 全部修改以前的文件,不然以前保存的文件都将不存在.app
若是由于某些缘由你发现本身处在一个混乱的状态中而后只是想要重来一次,也能够运行 git reset --hard HEAD
回到以前的状态或其余你想要恢复的状态。 请牢记这会将清除工做目录中的全部内容,因此确保你不须要保存这里的任意改动。fetch
if your want drop any change from the head and not commit the change,you can use :this
git reset --hard head ##remember every changes will not savedspa
Undoing a commit is a little scary if you don't know how it works. But it's actually amazingly easy if you do understand.rest
Say you have this, where C is your HEAD and (F) is the state of your files.code
(F) A-B-C ↑ master
You want to nuke commit C and never see it again. You do this:orm
git reset --hard HEAD~1
The result is:ip
(F) A-B ↑ master
Now B is the HEAD. Because you used --hard
, your files are reset to their state at commit B.rem
Undo add
$ edit (1) $ git add frotz.c filfre.c $ mailx (2) $ git reset (3) $ git pull git://info.example.com/ nitfol (4)
You are happily working on something, and find the changes in these files are in good order. You do not want to see them when you run "git diff", because you plan to work on other files and changes with these files are distracting.
Somebody asks you to pull, and the changes sounds worthy of merging.
However, you already dirtied the index (i.e. your index does not match the HEAD commit). But you know the pull you are going to make does not affect frotz.c or filfre.c, so you revert the index changes for these two files. Your changes in working tree remain there.
Then you can pull and merge, leaving frotz.c and filfre.c changes still in the working tree.
Undo a commit and redo
$ git commit ... $ git reset --soft HEAD^ (1) $ edit (2) $ git commit -a -c ORIG_HEAD (3)
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset".
Make corrections to working tree files.
"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.
git commit 后面加上以下参数的做用
-C <commit>
--reuse-message=<commit>
Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
-c <commit>
--reedit-message=<commit>
Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.