Git的幾個經常使用命令


git config

sh#git config 用來配置一些基本信息,最經常使用的以下
git config --global user.name "suemi"
git config --global user.email suemi94@qq.com
git config --global core.editor vim

git remote

shellgit remote add origin ssh:....#增長遠程倉庫origin,遠程倉庫名爲origin時能夠不帶
git remote #查看有哪些遠程倉庫

git branch

shellgit branch #查看本地分支
git branch -r origin #查看遠程倉庫分支
git branch -d work#刪除work分支
git branch jj#新建本地jj分支
git checkout work#切換到本地work分支
git checkout

git clone

這個沒什麼好說的,用的太多了git

git pull

shellgit pull origin work:master#拉取遠程倉庫origin的work分支到本地的master分支上,通常用於別人提交了後使用
git fetch origin work # 拉取遠程倉庫origin的work分支
git diff origin/work..master #查看兩分支的差別
git merge origin/work#在當前分支上合併origin/work

git push

shellgit push origin master:work#推送本地master分支到遠程倉庫origin的work分支上
gut push origin :work#刪除遠端的work分支
git push -f 強制push,哪怕遠程分支的commit記錄比你新

git commit

shellgit commit -a -m "first commit"
#操做文件
git commit --amend#將以後的操做補上去,最終只提交了一次

git status

shellgit status#查看當前狀態

git diff

shellgit dff#顯示尚未保存的改動
git diff --cached#顯示已經保存和最近提交之間的差別

git 撤銷的操做,最好在push以前作

shellgit revert 會用一個新的 commit 來回復全部的變更(適合已經push出去給別人的情境)。
git revert HEAD#撤銷前一次提交
git revert HEAD^#撤銷前前次提交
git revert 5962845b0059f9e7702b73066e6a35aea1efaa49#撤銷特定某次提交

git reset HEAD^ 就會回到前一版本,適合發現前一次 commit 有問題或是想要修改 commit log,能夠修改後再從新 commit。你在文件所作的修改下次依然會提交
git reset –hard HEAD^ 則會徹底抹掉前一次的 commit。

git rebase 會直接從新構建你的commit history,不推薦使用

最後,小提醒:工做以前先看看別人有沒有提交,push以前看看有沒有更新,優先推薦git fetch,還有在push以後就不要使用commit --amend了shell

注意:你想push的分支絕對不能有你本地所沒有的commit,也不能有與本地分支記錄不一致的commit
詳細解釋能夠參考Git 初學指南vim

相關文章
相關標籤/搜索