git中取消对文件的修改

有的时候我们在本地修改了一个文件,但是又不想修改了,怎么办

git checkout方式


hui.qian@HUIQIANPC /e/testerhome/chimpchat (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   src/com/android/chimpchat/ChimpChat.java

no changes added to commit (use "git add" and/or "git commit -a")

hui.qian@HUIQIANPC /e/testerhome/chimpchat (master)
$ git checkout src/com/android/chimpchat/ChimpChat.java

hui.qian@HUIQIANPC /e/testerhome/chimpchat (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

hui.qian@HUIQIANPC /e/testerhome/chimpchat (master)

用git checkout 的方式来撤销修改,有风险。当你在分支上已经提交了好几次commit,这个时候如果用git checkout的话,会把前几次修改都丢弃掉。那怎么办?

你可能感兴趣的:(工具学习[git])