git 删除以及回退

413 阅读1分钟

## delete file

有三种情况

add before

rm rf fileName

add after and commit before

git rm --cached <file> #remove from cache,file will be untracked
git rm -f <file> #delete file forced

second add and commit before

git reset HEAD <file> #remove from cache,file will be untracked

commit after

rm -rf c.txt
#delete file
git add c.txt #git rm c.txt
git commit -m "delete file"
#or discard  changes in the 
git checkout -- c.txt

git commit time metaphor

The HEAD pointer is the reference to the last commit we did or the parent of the next commit we will do.So,the HEAD pointer is the road sign that indicates the way to move one step back to the past.

git reset --hard HEAD # go back the last commit,
#在我们commit后修改了文件,可以回退到上一次版本