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(遠程分支名)