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.