久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      3招搞定!保持清潔的Git提交記錄

      本篇文章給大家?guī)?lái)了關(guān)于保持清潔的Git提交記錄的相關(guān)知識(shí),其中包括了“git commit –amend”、“git rebase -i”和“rebase”的相關(guān)問(wèn)題,希望對(duì)大家有幫助。

      3招搞定!保持清潔的Git提交記錄

      推薦學(xué)習(xí):《Git教程》

      大家都有學(xué)習(xí)如何規(guī)范簡(jiǎn)潔的 編寫代碼 ,但卻很少學(xué)習(xí)如何規(guī)范簡(jiǎn)潔的 提交代碼 ?,F(xiàn)在大家基本上都用 Git 作為源碼管理的工具,Git 提供了極大的靈活性,我們按照各種 workflow 來(lái)提交/合并 code,這種靈活性把控不好,也會(huì)帶來(lái)很多問(wèn)題

      最常見的問(wèn)題就是亂成一團(tuán)的 git log history,那真的是老太太的裹腳布, 又臭又長(zhǎng), 個(gè)人極其不喜歡這種 log

      3招搞定!保持清潔的Git提交記錄

      造成這個(gè)問(wèn)題的根本原因就是隨意提交代碼。

      代碼都提交了,那還有什么辦法拯救嗎?三個(gè)錦囊,就可以完美解決了

      善用 git commit –amend

      這個(gè)命令的幫助文檔是這樣描述的:

      --amend               amend previous commit

      也就是說(shuō),它可以幫助我們修改 最后一次提交

      既可以修改我們提交的 message,又可以修改我們提交的文件,最后還會(huì)替換最后一個(gè) commit-id

      我們可能會(huì)在某次提交的時(shí)候遺漏了某個(gè)文件,當(dāng)我們?cè)俅翁峤痪涂赡軙?huì)多處一個(gè)無(wú)用的 commit-id,大家都這樣做,git log 慢慢就會(huì)亂得無(wú)法追蹤完整功能了

      假設(shè)我們有這樣一段 log 信息

      * 98a75af (HEAD -> feature/JIRA123-amend-test) feat: [JIRA123] add feature 1.2 * 119f86e feat: [JIRA123] add feature 1.1 * 5dd0ad3 feat: [JIRA123] add feature 1 * c69f53d (origin/main, origin/feature/JIRA123-amend-test, origin/HEAD, main) Initial commit

      假設(shè)我們要修改最后一個(gè) log message,就可以使用下面命令:

      git commit --amend -m "feat: [JIRA123] add feature 1.2 and 1.3"

      我們?cè)賮?lái)看一下 log 信息, 可以發(fā)現(xiàn),我們用新的 commit-id 5e354d1 替換了舊的 commit-id 98a75af , 修改了 message,并沒(méi)有增加節(jié)點(diǎn)

      * 5e354d1 (HEAD -> feature/JIRA123-amend-test) feat: [JIRA123] add feature 1.2 and 1.3 * 119f86e feat: [JIRA123] add feature 1.1 * 5dd0ad3 feat: [JIRA123] add feature 1 * c69f53d (origin/main, origin/feature/JIRA123-amend-test, origin/HEAD, main) Initial commit

      現(xiàn)在我們的 repo 中文件是這樣的:

      . ├── README.md └── feat1.txt  0 directories, 2 files

      假設(shè)我們提交 feature 1.3 的時(shí)候,忘記了一個(gè)配置文件 config.yaml , 不想修改 log,不想添加新的 commit-id,那下面的這個(gè)命令就非常好用了

      echo "feature 1.3 config info" > config.yaml git add . git commit --amend --no-edit

      git commit –amend –no-edit 就是靈魂所在了,來(lái)看一下當(dāng)前的 repo 文件:

      . ├── README.md ├── config.yaml └── feat1.txt  0 directories, 3 files

      再來(lái)看一下 git log

      * 247572e (HEAD -> feature/JIRA123-amend-test) feat: [JIRA123] add feature 1.2 and 1.3 * 119f86e feat: [JIRA123] add feature 1.1 * 5dd0ad3 feat: [JIRA123] add feature 1 * c69f53d (origin/main, origin/feature/JIRA123-amend-test, origin/HEAD, main) Initial commit

      知道這個(gè)技巧,就可以確保我們的每次提交都包含有效的信息了。一張圖描述這個(gè)過(guò)程就是這個(gè)樣子了:

      3招搞定!保持清潔的Git提交記錄

      有了 –no-edit 的 buff 加成,威力更大一些

      善用 git rebase -i

      可以看著,上面的 log 都是在開發(fā) feature1,我們?cè)诎?feature 分支 merge 到 main 分支之前,還是應(yīng)該繼續(xù)合并 log commit 節(jié)點(diǎn)的,這就用到了

      git rebase -i HEAD~n

      其中 n 代表最后幾個(gè)提交,上面我們針對(duì) feature 1 有三個(gè)提交,所以就可以使用:

      git rebase -i HEAD~3

      運(yùn)行后,會(huì)顯示一個(gè) vim 編輯器,內(nèi)容如下:

       1 pick 5dd0ad3 feat: [JIRA123] add feature 1  2 pick 119f86e feat: [JIRA123] add feature 1.1  3 pick 247572e feat: [JIRA123] add feature 1.2 and 1.3  4  5 # Rebase c69f53d..247572e onto c69f53d (3 commands)  6 #  7 # Commands:  8 # p, pick <commit> = use commit  9 # r, reword <commit> = use commit, but edit the commit message 10 # e, edit <commit> = use commit, but stop for amending 11 # s, squash <commit> = use commit, but meld into previous commit 12 # f, fixup <commit> = like "squash", but discard this commit's log message 13 # x, exec <command> = run command (the rest of the line) using shell 14 # d, drop <commit> = remove commit 15 # l, label <label> = label current HEAD with a name 16 # t, reset <label> = reset HEAD to a label 17 # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] 18 # .       create a merge commit using the original merge commit's 19 # .       message (or the oneline, if no original merge commit was 20 # .       specified). Use -c <commit> to reword the commit message. 21 # 22 # These lines can be re-ordered; they are executed from top to bottom. 23 # 24 # If you remove a line here THAT COMMIT WILL BE LOST. 25 # 26 #   However, if you remove everything, the rebase will be aborted. 27 # 28 # 29 # Note that empty commits are commented out

      合并 commit-id 最常用的是 squash 和 fixup , 前者包含 commit message,后者不包含,這里使用 fixup, 然后 :wq 退出

      1 pick 5dd0ad3 feat: [JIRA123] add feature 1 2 fixup 119f86e feat: [JIRA123] add feature 1.1 3 fixup 247572e feat: [JIRA123] add feature 1.2 and 1.3

      我們?cè)賮?lái)看一下 log, 這就非常清晰了

      * 41cd711 (HEAD -> feature/JIRA123-amend-test) feat: [JIRA123] add feature 1 * c69f53d (origin/main, origin/feature/JIRA123-amend-test, origin/HEAD, main) Initial commit

      善用 rebase

      上面的 feature1 已經(jīng)完整地開發(fā)完了,main 分支也有了其他人的更新,再將 feature merge 回 main 分支之前,以防代碼有沖突,需要先將 main 分支的內(nèi)容合并到 feature 中,如果用 merge 命令,就會(huì)多處一個(gè) merge 節(jié)點(diǎn),log history 中也會(huì)出現(xiàn)拐點(diǎn),并不是線性的,所以這里我們可以在 feature 分支上使用 rebase 命令

      git pull origin main --rebase

      3招搞定!保持清潔的Git提交記錄

      pull 命令的背后是自動(dòng)幫我們做 merge 的,但是這里以 rebase 的形式,再來(lái)看一下 log

      * d40daa6 (HEAD -> feature/JIRA123-amend-test) feat: [JIRA123] add feature 1 * 446f463 (origin/main, origin/HEAD) Create main.properties * c69f53d (origin/feature/JIRA123-amend-test, main) Initial commit

      我們的 feature1 功能 on top of main 的提交節(jié)點(diǎn),還是保持線性,接下來(lái)就可以 push 代碼,然后提 PR,將你的 feature merge 到 main 分支了

      簡(jiǎn)單描述 merge 和 rebase 的區(qū)別就是這樣的:

      3招搞定!保持清潔的Git提交記錄

      我這里使用 git pull origin main –rebase 省略了切換 main 并拉取最新內(nèi)容再切回來(lái)的過(guò)程,一步到位,背后的原理都是上圖展示的這樣

      使用 rebase 是要遵守一個(gè)黃金法則的,這個(gè)之前有說(shuō)過(guò),就不再是贅述了

      總結(jié)

      有了這三個(gè)錦囊,相信大家的 git log 都無(wú)比的清晰,如果你還不知道,完全可以用起來(lái),如果你的組內(nèi)成員不知道,你完全可以推廣起來(lái),這樣的 repo 看起來(lái)才更健康

      推薦學(xué)習(xí):《Git教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)