git日常操作

Git日常使用命令

創(chuàng)建版本庫

git clone < 版本庫的網(wǎng)址 > < 本地目錄名 > #克隆遠程版本庫

git init #初始化本地版本庫

修改和提交

git status #查看狀態(tài)

git diff #查看變更內(nèi)容

git add . #跟蹤所有改動過的文件

git add < file > #跟蹤指定的文件

git mv < old > < new > #文件改名

git rm < file > #刪除文件

git rm –cached < file > #停止跟蹤文件但不刪除

git commit -m “commit message” #提交所有更新過的文件

git commit –amend #修改最后一次提交

查看提交歷史

git log #查看提交歷史

git log -p < file > #查看指定文件的提交歷史

git blame < file > #以列表方式查看指定文件的提交歷史

撤消

git reset –hard HEAD #撤消工作目錄中所有未提交文件的修改內(nèi)容

git checkout HEAD < file > #撤消指定的未提交文件的修改內(nèi)容

git revert < commit > #撤消指定的提交

分支與標簽

git branch #顯示所有本地分支

git branch -a#顯示所有分支

git branch -r#顯示所有遠程分支

git checkout < branch/tag > #切換到指定分支或標簽

git branch < new-branch > #創(chuàng)建新分支

git branch -d < branch > #刪除本地分支

git tag #列出所有本地標簽

git tag < tagname > #基于最新提交創(chuàng)建標簽

git tag -d < tagname > #刪除標簽

合并與衍合

git merge < branch > #合并指定分支到當前分支

git rebase < branch > #衍合指定分支到當前分支

遠程操作

git remote #列出所有遠程主機

git remote -v #查看遠程版本庫信息

git remote show < remote > #查看指定遠程版本庫信息

git remote add < remote > < url > #添加遠程版本庫

git fetch < remote > #從遠程庫獲取代碼

git fetch < remote > < branch > #取回遠程庫的分支

git pull < remote > < branch > #下載代碼及快速合并

git pull < remote > < branch >:< local_branch >#下載代碼與本地分支合并,默認采用merge模式合并

git pull –rebase < remote > < branch >:< local_branch > #下載代碼與本地采用rebase模式合并

git push < remote > < branch > #上傳代碼及快速合并

git push < remote > < local_branch >:< remote_branch > #上傳分支數(shù)據(jù)到遠程

git push < remote > :< branch/tag-name > #刪除遠程分支或標簽

git push –tags #上傳所有標簽

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容