git的常用操作指令
命令 | 實現操作 | 備註 |
---|---|---|
git init | 在現有目錄中初始化倉庫 | |
git add | 對指定文件的跟蹤 | 後面接你想跟蹤的文件 |
git commit | 提交更新 | |
git clone | 克隆現有的倉庫 | 後面接你的git庫地址 |
git status | 檢查當前文件狀態 | |
git diff | 檢查具體修改了什麼地方 | |
git diff --cached | 把已暫存的添加到下次提交裏的內容 | 與git diff --staged類似 |
git rm | 移除文件 | |
git log | 查看提交歷史 | |
git commit --amend | 撤消操作 | |
git reset HEAD | 取消暫存的文件 | |
git checkout – [file] | 撤消對文件的修改 | 這是一個危險的命令,你對那個文件做的任何修改都會消失 |
git remote | 查看遠程倉庫 | git remote -v會顯示需要讀寫遠程倉庫使用的 Git 保存的簡寫與其對應的 URL。 |
git remote add | 添加遠程倉庫 | git remote add pb https://github.com/paulboone/ticgit |
git fetch pb | 拉取pb 的倉庫中有但你沒有的信息 | git fetch [remote-name] |
git push origin master | 推送到遠程倉庫 | git push [remote-name] [branch-name] |
git remote show origin | 查看遠程倉庫 | git remote show [remote-name] |
git remote rename | 遠程倉庫的重命名 | git remote rename pb paul(pb 重命名爲 paul) |
git remote rm | 遠程倉庫的重命名移除 | git remote rm paul(移除paul) |
git tag | 列出標籤 | |
git branch testing | 創建分支 | |
git checkout testing | 分支切換 | |
git checkout -b iss53 | 新建分支iss53 | |
git branch -d hotfix | 刪除分支hotfix | |
git checkout master / git merge iss53 | 合併分支 | 把分支iss53 合併到分支master 上 |
git mergetool | 遇到衝突時的分支合併 | 會啓動一個合適的可視化合並工具,並帶領你一步一步解決這些衝突 |
git branch -v | 查看每一個分支的最後一次提交 | |
git branch --merged | 查看哪些分支已經合併到當前分支 | |
git branch --no-merged | 查看所有包含未合併工作的分支 | |
git fetch | 更新你的遠程倉庫引用 (拉取) | |
git fetch teamone | 來抓取遠程倉庫 teamone 有而本地沒有的數據 | Git 並不會抓取數據而是會設置遠程跟蹤分支 teamone/master 指向 teamone 的 master 分支 |
git pull | 跟蹤分支 | Git 能自動地識別去哪個服務器上抓取、合併到哪個分支。 |
git push origin --delete serverfix | 從服務器上刪除 serverfix 分支 |
以上爲自己整理的一些git常用操作指令,後續若有新增會持續更新