git常用命令表

來源:互聯網
上載者:User

標籤:rem   --   init   stat   git fetch   撤銷   git init   url   code   

本文主要是用來記錄一些在git管理的項目中常見的情境及其對應的命令,方便自己和他人使用的時候快速查詢。如有不對,敬請指正。

查看某個git命令的協助文檔

git help [command]

查看各個檔案的狀態

git status

clone一個倉庫

git clone [url]

初始化一個倉庫

git init

將檔案放到暫存區

git add [file-name]

提交

git commit

停止追蹤檔案並刪除檔案

git rm [file-name]

停止跟蹤並刪除已修改且添加到暫存區的檔案

git rm -f [file-name]

停止跟蹤但不刪除檔案

git rm --cached [file-name]

移動檔案或修改檔案名稱

git mv [old-name] [new-name]

顯示已經放到暫存區的檔案的修改

git diff --cached

顯示未放到暫存區的檔案的修改

git diff [path/to/file]

顯示當前倉庫的所有本地分支

git branch

顯示當前倉庫的所有遠程分支

git branch -r

顯示當前倉庫的所有分支(包括本地和遠程)

git branch -a

建立一個本地分支

git branch [branch-name]

切換到某個本地分支

git checkout [branch-name]

將某個分支合并到當前分支

git merge [branch-name]

刪除已經被合并的分支

git branch -d [branch-name]

刪除還未被合并的分支

git branch -D [branch-name]

合并代碼後還未提交,此時希望撤銷合并

git reset --hard HEAD

查看所有的提交

git log

查看所有提交及每個提交對應的代碼diff

git log -p

查看所有提交,以及每個提交涉及的檔案,以及這些檔案刪除/添加了多少行

git log --stat

查看當前工作目錄與某個分支的差別

git diff [branch-name]

查看當前工作目錄下的某個目錄與某個分支的差別

git diff [branch-name] -- [path]

修改最後一次提交

git commit --amend

撤銷已暫存的檔案

git reset HEAD [file-name]

撤銷對檔案的修改

git checkout -- [file-name]

查看當前配置的遠程倉庫

git remote

查看當前配置的遠程倉庫和對應的地址

git remote -v

添加遠程倉庫

git remote add [remote-name] [url]

從遠程倉庫抓去資料

git fetch [remote-name] [branch-name]

推送資料到遠程倉庫

git push [remote-name] [branch-name]

查看某個遠程倉庫資訊

git remote show [remote-name]

重新命名遠程倉庫

git remote rename [old-name] [new-name]

刪除某個遠程倉庫

git remote rm [remote-name]

顯示已有的標籤

git tag

搜尋特定tag

git tag -l [keyword]

建立輕量級標籤

git tag [tag-name]

建立含附註標籤

git tag -a [tag-name] -m [msg]

給之前的某個提交加標籤

git tag -a [tag-name] [hash]

查看某個標籤的資訊

git show [tag-name]

將標籤推送到遠程倉庫

git push [remote-name] [tag-name]

將所有本地標籤一次推送到遠程倉庫

git push [remote-name] --tags

將分支b衍合入分支a

git checkout b git rebase a

切換到另一個分支前,你並不想把當前分支上的修改提交的話,可以使用儲藏功能

git stash

顯示所有儲藏

git stash list

應用你的儲藏

git stash apply [stash-name] 

git常用命令表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.