git init
創建本地倉庫
git log
查看提交歷史,已確定要回退到哪個版本
git reflog
查看命令歷史,以便確定要回到未來的哪個版本
git reset --hard commit_id
回退版本
git add file
添加文件或修改到暫存區
git add --all
添加所有修改到暫存區(or git add .
)
git commit -m "introduction"
提交更改至倉庫
git status
查看文件狀態
git checkout --file
撤銷掉關於file文件的工作區的修改,即讓文件回到最近一次git commit
或git add
時的狀態
git checkout .
撤銷掉所有關於工作區更改
git reset HEAD file
撤銷掉關於file文件的暫存區的修改
git reset --hard
強制回退到提交之前的狀態
git fsck --lost-found
在本地項目文件中路徑爲.git/lost-found/other中找到已經add但沒有commit的文件(一般是在錯誤使用git reset --hard
後補償用 )
git stash
把所有沒有提交的修改暫存到stash裏面。可用git stash pop回覆
git remote add name URL
關聯遠程倉庫
git push origin first:master
推送本地first分支至origin主機遠程的master分支,如果遠程沒有則創建
git pull origin first:master
取回origin主機的first分支並與本地master合併
git fetch origin master
取回origin主機的master分支
git merge origin/master
與本地當前分支合併
git fetch orgin master:tmp
從遠程倉庫master分支獲取最新,在本地建立tmp分支
git diff tmp
將當前分支和tmp進行對比
git merge tmp
合併tmp分支到當前分支
git branch -r/-a
查看遠程分支/所有分支
git branch tmp
本地創建分支tmp
git checkout tmp
切換分支到tmp
git branch -d tmp
刪除本地tmp分支
git push orgin --delete tmp
刪除遠程orgin上的tmp分支