git reset --soft <commit_id> 会将改动放在缓存区 git
git reset --mixed <commit_id> 不把改动放在缓存区缓存
git reset –hard <commit_id>
app
tip: <commit_id>: 要撤销的前面一个commitfetch
缓存区 : add的代码就在缓存区spa
git commit -m 'initial commit' code
git add forgotten_fileip
git commit --amendrem
tip:上面的三条命令最终只是产生一个提交,第二个提交命令修正了第一个的提交内容同步
git reset HEAD <file>string
git checkout -- <file>
git reset --merge
tip:由于pull操做实际上包含了fetch+merge操做
git stash //可以将全部未提交的修改(工做区和暂存区)保存至堆栈中,用于后续恢复当前工做目录
git stash save "remark" //做用等同于git stash,区别是能够加一些注释
git stash list //查看当前stash中的内容
git stash pop //将当前stash中的内容弹出,并应用到当前分支对应的工做目录上。
tip:注:该命令将堆栈中最近保存的内容删除(栈是先进后出)
git stash apply //将堆栈中的内容应用到当前目录
git stash apply <stash_name> //指定恢复哪一个stash到当前的工做目录
tip:不一样于git stash pop,该命令不会将内容从堆栈中删除,也就说该命令可以将堆栈的内容屡次应用到工做目录中,适应于多个分支的状况
git stash drop <stash_name> //从堆栈中移除某个指定的stash
git stash clear //清除堆栈中的全部内容
git rm -r --cached .
git add .
git commit -m
'update .gitignore'
tip:把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,缘由是.gitignore只能忽略那些原来没有被追踪的文件,若是某些文件已经被归入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未被追踪状态),而后再提交,这样就不会出现忽略的文件了
git fetch origin --prune
git checkout -b dev(本地分支名) origin/dev(远程分支名)