日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简明 Git 命令速查表

發(fā)布時間:2025/6/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简明 Git 命令速查表 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文總結了git常用的命令,以便學習者使用時查閱~

?

幾個專用名詞的譯名如下

  • Workspace:工作區(qū)
  • Index / Stage:暫存區(qū)
  • Repository:倉庫區(qū)(或本地倉庫)
  • Remote:遠程倉庫

?

復制一個已創(chuàng)建的倉庫:

git clone ssh://user@domain.com/repo.git

創(chuàng)建一個新的本地倉庫:

git init

顯示工作路徑下已修改的文件:

git status

顯示與上次提交版本文件的不同:

git diff

把當前所有修改添加到下次提交中:

git add

把對某個文件的修改添加到下次提交中:

git add -p <file>

提交本地的所有修改:

git commit -a

提交之前已標記的變化:

git commit

附加消息提交:

git commit -m 'message here'

提交,并將提交時間設置為之前的某個日期:

git commit --date="`date --date='n day ago'`" -am "Commit Message"

修改上次提交
請勿修改已發(fā)布的提交記錄!

git commit --amend

把當前分支中未提交的修改移動到其他分支

git stash git checkout branch2 git stash pop

列出所有stash

git stash list

查看一個stash

git show stash@{0}

刪除一個stash

git stash drop stash@{0}

將指定的stash取出來

git stash apply stash@{1}

將最后一個stash取出來,并刪除掉隊列中相應的值

git stash pop

清空所有stash

git stash clear

從當前目錄的所有文件中查找文本內容:

git grep "Hello"

在某一版本中搜索文本:

git grep "Hello" v2.5

從最新提交開始,顯示所有的提交記錄(顯示hash, 作者信息,提交的標題和時間):

git log

顯示所有提交(僅顯示提交的hash和message):

git log --oneline

顯示某個用戶的所有提交:

git log --author="username"

顯示某個文件的所有修改:

git log -p <file>

誰,在什么時間,修改了文件的什么內容:

git blame <file>

列出所有的分支:

git branch

列出所有的分支以及其對應的遠端分支:

git branch -vv

切換分支:

git checkout <branch>

創(chuàng)建并切換到新分支:

git checkout -b <branch>

基于當前分支創(chuàng)建新分支:

git branch <new-branch>

基于遠程分支創(chuàng)建新的可追溯的分支:

git branch --track <new-branch> <remote-branch>

刪除本地分支:

git branch -d <branch>

給當前版本打標簽:

git tag <tag-name>

獲取本地標簽:

git tag

刪除一個本地標簽:

git tag -d <tag-name>

刪除一個遠端標簽:

git push origin :refs/tags/<tag-name>

發(fā)布標簽:

git push --tags

列出當前配置的遠程端:

git remote -v

顯示遠程端的信息:

git remote show <remote>

添加新的遠程端:

git remote add <remote> <url>

下載遠程端版本,但不合并到HEAD中:

git fetch <remote>

下載遠程端版本,并自動與HEAD版本合并:

git remote pull <remote> <url>

將遠程端版本合并到本地版本中:

git pull origin master

將本地版本發(fā)布到遠程端:

git push remote <remote> <branch>

將本地branch1發(fā)布到遠程端branch2:

git push origin <branch1>:<branch2>

刪除遠程端分支:

git push <remote> :<branch> (since Git v1.5.0) git push <remote> --delete <branch> (since Git v1.7.0)

將分支合并到當前HEAD中:

git merge <branch>

將當前HEAD版本重置到分支中:
請勿重置已發(fā)布的提交!

git rebase <branch>

退出重置:

git rebase --abort

解決沖突后繼續(xù)重置:

git rebase --continue

使用配置好的merge tool 解決沖突:

git mergetool

在編輯器中手動解決沖突后,標記文件為已解決沖突

git add <resolved-file> git rm <resolved-file>

兩個分支的合并,將other-branch合并到main-branch中

git checkout <other-branch> git rebase <main-branch> git checkout <main-branch> git merge <other-branch>

放棄工作目錄下的所有修改:

git reset --hard HEAD

移除緩存區(qū)的所有文件(i.e. 撤銷上次git add):

git reset HEAD

放棄某個文件的所有本地修改:

git checkout HEAD <file>

重置一個提交(通過創(chuàng)建一個截然不同的新提交)

git revert <commit>

將HEAD重置到指定的版本,并拋棄該版本之后的所有修改:

git reset --hard <commit>

將HEAD重置到上一次提交的版本,并將之后的修改標記為未添加到緩存區(qū)的修改:

git reset <commit>

將HEAD重置到上一次提交的版本,并保留未提交的本地修改:

git reset --keep <commit>

?

最后附一張完整展示git流程的圖片

?

參考:

http://www.codeceo.com/article/git-command-guide.html

http://www.ruanyifeng.com/blog/2014/06/git_remote.html

http://git-scm.com/doc

?

總結

以上是生活随笔為你收集整理的简明 Git 命令速查表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。