Git 常用命令

2021-10-11 06:00:32 字數 1875 閱讀 7266

git 常用命令整理

1.建立版本庫

$ git clone                   #轉殖遠端版本庫

$ git init #初始化本地版本庫

2.修改和提交

$ git status                       #檢視狀態

$ git diff #檢視變更內容

$ git add

. #跟蹤所有改動過的檔案

$ git add

#跟蹤指定的檔案

$ git mv

<

new> #檔案改名

$ git rm #刪除檔案

$ git rm --cached #停止跟蹤檔案但不刪除

$ git commit -m "commit messages"

#提交所有更新過的檔案

$ git commit --amend #修改最後一次改動

3.檢視提交歷史

$ git log                    #檢視提交歷史

$ git log -p #檢視指定檔案的提交歷史

$ git blame #以列表方式檢視指定檔案的提交歷史

4.撤銷

$ git reset --hard head      #撤銷工作目錄中所有未提交檔案的修改內容

$ git checkout head #撤銷指定的未提交檔案的修改內容

$ git revert #撤銷指定的提交

$ git log --before=

"1 days"

#退回到之前1天的版本

5.分支與標籤

$ git branch                   #顯示所有本地分支

$ git checkout

#切換到指定分支和標籤

$ git branch <

new-branch> #建立新分支

$ git branch -d

#刪除本地分支

$ git tag #列出所有本地標籤

$ git tag #基於最新提交建立標籤

$ git tag -d #刪除標籤

6.合併與衍合

$ git merge 

#合併指定分支到當前分支

$ git rebase

#衍合指定分支到當前分支

7.遠端操作

$ git remote -v                   #檢視遠端版本庫資訊

$ git remote show #檢視指定遠端版本庫資訊

$ git remote add

#新增遠端版本庫

$ git fetch #從遠端庫獲取**

$ git pull

$ git push

#上傳**及快速合併

$ git push

: #刪除遠端分支或標籤

$ git push --tags #上傳所有標籤

以上 整理一下以備使用

常用命令 Git 常用命令大全

安裝教程可參照 廖雪峰老師的安裝教程。git config 在git中,使用git config 命令來配置 git 的配置檔案,git配置級別主要有3類 1 倉庫級別 local 本地 git 倉庫級別配置檔案,作用於當前倉庫。優先順序最高 2 使用者級別 global,全域性配置檔案,作用於所有...

git 常用命令

檢視是否存在檔案需要上傳 git status git add git commit m 建立遠端倉庫 git remote add origin 116.255.146.153 ruby cd work daily project.git 更新git fetch 116.255.146.153 r...

git常用命令

詳細 1,git log p 命令來顯示每一次提交與其父節點提交內容之間快照的差異。2,為了檢視載入 staged 而並未提交 not committed 的內容差異,可以使用 git diff stage 命令 在git 1.6之前的版本中,使用 cached 適應情形 在執行git commit...