<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          41個(gè)Git 命令備忘清單

          共 2728字,需瀏覽 6分鐘

           ·

          2022-11-22 11:01

          英文 | https://tapajyoti-bose.medium.com/git-cheat-sheet-with-40-commands-concepts-ab1b9d973e96

          翻譯 | 楊小愛


          厭倦了記繁瑣的Git 命令?沒有關(guān)系,今天,我就為你準(zhǔn)備了一份包含 41 個(gè)Git命令的備忘單,這些清單可提高你的工作效率,讓你擁有更多的業(yè)余時(shí)間,從而更好的享受屬于自己的生活。
          那我們現(xiàn)在開始吧。
          1、初始化本地倉庫
          git init <directory>

          <directory> 是可選的,如果不指定,將使用當(dāng)前目錄。

          2.克隆一個(gè)遠(yuǎn)程倉庫

          git clone <url>

          3.添加文件到暫存區(qū)

          git add <file>

          要添加當(dāng)前目錄中的所有文件,請(qǐng)使用 . 代替 <file>,代碼如下:

          git add .

          4. 提交更改

          git commit -m "<message>"

          如果要添加對(duì)跟蹤文件所做的所有更改并提交。

          git commit -a -m "<message>"
          # or
          git commit -am "<message>"

          5.從暫存區(qū)刪除一個(gè)文件

          git reset <file>

          6.移動(dòng)或重命名文件

          git mv <current path> <new path>

          7. 從存儲(chǔ)庫中刪除文件

          git rm <file>

          您也可以僅使用 --cached 標(biāo)志將其從暫存區(qū)中刪除

          git rm --cached <file>

          基本 Git 概念

          8.默認(rèn)分支名稱:main

          9.默認(rèn)遠(yuǎn)程名稱:origin

          10.當(dāng)前分支參考:HEAD

          11. HEAD 的父級(jí):HEAD^ 或 HEAD~1

          12. HEAD 的祖父母:HEAD^^ 或 HEAD~2

          13. 顯示分支

          git branch

          有用的標(biāo)志:

          -a:顯示所有分支(本地和遠(yuǎn)程)

          -r:顯示遠(yuǎn)程分支

          -v:顯示最后一次提交的分支

          14.創(chuàng)建一個(gè)分支

          git branch <branch>

          你可以創(chuàng)建一個(gè)分支并使用 checkout 命令切換到它。

          git checkout -b <branch>

          15.切換到一個(gè)分支

          git checkout <branch>

          16.刪除一個(gè)分支

          git branch -d <branch>

          您還可以使用 -D 標(biāo)志強(qiáng)制刪除分支。

          git branch -D <branch>

          17.合并分支

          git merge <branch to merge into HEAD>

          有用的標(biāo)志:

          --no-ff:即使合并解析為快進(jìn),也創(chuàng)建合并提交

          --squash:將指定分支中的所有提交壓縮為單個(gè)提交

          快進(jìn)合并

          非快進(jìn)合并

          建議不要使用 --squash 標(biāo)志,因?yàn)樗鼤?huì)將所有提交壓縮為單個(gè)提交,從而導(dǎo)致提交歷史混亂。

          18. 變基分支

          變基是將一系列提交移動(dòng)或組合到新的基本提交的過程。

          git rebase <branch to rebase from>

          19. 查看之前的提交

          git checkout <commit id>

          20. 恢復(fù)提交

          git revert <commit id>

          21. 重置提交

          git reset <commit id>

          您還可以添加 --hard 標(biāo)志來刪除所有更改,但請(qǐng)謹(jǐn)慎使用。

          git reset --hard <commit id>

          22.查看存儲(chǔ)庫的狀態(tài)

          git status

          23.顯示提交歷史

          git log

          24.顯示對(duì)未暫存文件的更改

          git diff

          您還可以使用 --staged 標(biāo)志來顯示對(duì)暫存文件的更改。

          git diff --staged

          25.顯示兩次提交之間的變化

          git diff <commit id 01> <commit id 02>

          26. 存儲(chǔ)更改

          stash 允許您在不提交更改的情況下臨時(shí)存儲(chǔ)更改。

          git stash

          您還可以將消息添加到存儲(chǔ)中。

          git stash save "<message>"

          27. 列出存儲(chǔ)

          git stash list

          28.申請(qǐng)一個(gè)藏匿處

          應(yīng)用存儲(chǔ)不會(huì)將其從存儲(chǔ)列表中刪除。

          git stash apply <stash id>

          如果不指定 <stash id>,將應(yīng)用最新的 stash(適用于所有類似的 stash 命令)

          您還可以使用格式 stash@{<index>} 應(yīng)用存儲(chǔ)(適用于所有類似的存儲(chǔ)命令)

          git stash apply stash@{0}

          29.刪除一個(gè)藏匿處

          git stash drop <stash id>

          30.刪除所有藏匿處

          git stash clear

          31. 應(yīng)用和刪除存儲(chǔ)

          git stash pop <stash id>

          32.顯示存儲(chǔ)中的更改

          git stash show <stash id>

          33.添加遠(yuǎn)程倉庫

          git remote add <remote name> <url>

          34. 顯示遠(yuǎn)程倉庫

          git remote

          添加 -v 標(biāo)志以顯示遠(yuǎn)程存儲(chǔ)庫的 URL。

          git remote -v

          35.刪除遠(yuǎn)程倉庫

          git remote remove <remote name>

          36.重命名遠(yuǎn)程存儲(chǔ)庫

          git remote rename <old name> <new name>

          37. 從遠(yuǎn)程存儲(chǔ)庫中獲取更改

          git fetch <remote name>

          38. 從特定分支獲取更改

          git fetch <remote name> <branch>

          39. 從遠(yuǎn)程存儲(chǔ)庫中拉取更改

          git pull <remote name> <branch>

          40.將更改推送到遠(yuǎn)程存儲(chǔ)庫

          git push <remote name>

          41.將更改推送到特定分支

          git push <remote name> <branch>

          寫在最后的想法

          以上就是我今天在這篇文章中與你分享的41個(gè)Git命令的列表清單,希望這些清單對(duì)你有用,也希望你能從中學(xué)習(xí)到新的命令,并將其應(yīng)用到你的開發(fā)中,如果你覺得今天內(nèi)容對(duì)你有幫助的話,請(qǐng)記得點(diǎn)贊我,關(guān)注我,并將這篇文章與你的開發(fā)者朋友們一起來分享它,也許能夠幫助到他們。
          最后,感謝你的閱讀,編程快樂!

          瀏覽 60
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  搞基操逼摸奶黄色视频网站 | 天天视频黄 | 色情网站免费观看在线观看 | 天天草天天爱 | 成人九九 |