git revertファイル

1057 ワード

svnを使う時は、ロールバックファイルを直接svn revertで使えばいいです.gitを使う時は、ロールバックしてもいいです.具体的には次のように使います.
最初の場合は、git addを実行していません.ファイルをロールバックします.
$ git status -s
 M test.c
$ git checkout -- test.c   // git revert
$ git status -s```
##         git add,      
```$ echo test >> test.c
$ git add test.c    // here is the different
$ git status -s
 M test.c
$ git reset --hard HEAD  // git revert, clean all tree
$ git status -s```

##         git add,      
```$ git add test.c   main.c 
$ git status -s
 M test.c
 M main.c
$ git reset test.c // unstage the change
$ git checkout test.c //  discard the unstaged change
$ git status -s```

#PS:
 [reverting-changes-git](http://www.szakmeister.net/blog/2011/oct/12/reverting-changes-git/)

#  
             ,       。

![   .jpg](http://upload-images.jianshu.io/upload_images/4765606-b13a42b44fd975a7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/340)


![  .jpg](http://upload-images.jianshu.io/upload_images/4765606-3ad5592b17125067.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/340)