常用GIT命令整理

命令 說明 例子
git init 初始化git倉庫
git remote add origin git@server-name:path/repo-name.git 關聯一個遠程庫
git clone 克隆遠程倉庫
git add < file > 添加文件到暫存區 git add .
git commit -m “xxx” 將暫存區文件提交到本地倉庫 git commit -m “Demo”
git status 查看當前倉庫狀態
git diff < file > 對比文件修改點 git diff ./abc.txt
git log 查看提交日誌
git log --graph 查看分支合併圖
git reflog 查看命令歷史
git reset --hard commit_id 回退到某個版本,HEAD指向的版本是當前版本,上一個版本:HEAD ^ ,上上個版本HEAD: ^^ ,上100個版本HEAD~100 git reset --hard HEAD^
git checkout – < file > 丟棄工作區的修改,add前 git checkout – ./abc.txt
git reset HEAD < file > 撤銷暫存區的修改,add後
git rm < file > 刪除文件
git push -u origin master 第一次推送master分支的所有內容
git push origin master 此後推送最新修改可以使用命令
git push origin branch-name 從本地推送分支
git checkout -b branch-name origin/branch-name 從本地創建和遠程分支對應的分支
git branch --set-upstream branch-name origin/branch-name 建立本地分支和遠程分支的關聯
git pull 從遠程抓取分支
git branch 查看分支
git branch < name > 創建分支
git checkout < name > 切換分支
git checkout -b < name > 創建+切換分支
git merge < name > 合併某分支到當前分支 git merge master
git branch -d < name > 刪除分支
git branch -D < name > 強制刪除一個沒有被合併過的分支
git stash 儲藏當前工作現場
git stash list 查看儲藏的工作現場
git stash apply 恢復工作現場(stash內容不會被刪除)
git stash drop 刪除stash內容
git stash pop 恢復的同時刪除stash內容
git remote -v 查看遠程庫信息
git tag < name > 新建一個標籤(默認HEAD,也可以指定commit id)
git tag -a < tagname > -m “xxx” 指定標籤信息
git tag -s < tagname > -m “xxx” 用PGP簽名標籤
git tag 查看所有標籤
git push origin < tagname > 推送本地標籤到遠程
git push origin --tags 推送全部未推送過的本地標籤
git tag -d < tagname > 刪除一個本地標籤
git push origin :refs/tags/< tagname > 刪除一個遠程標籤
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章