GitHub Copilot X CLI:你的新GIT助手

需要一些關於git命令的幫助?問問Copilot CLI吧!

GitHub Copilot X CLI:你的新GIT助手

GitHub Copilot CLI有三個別名:

  • ??::詢問一個通用的shell命令
  • git?:詢問一個 git 命令
  • gh?:詢問 GitHub CLI 命令

今天我玩了一下 git ? 來測試建議的準確性,以及獲得正確的命令有多容易。你可以在文章末尾的視訊找到。

劇透:如果你在不瞭解AI生成的命令的情況下執行這些命令,結果是……不可預知的 😅

無害的例子

在視訊的開頭,你會看到我問了一個相當簡單的問題,基本上是從main建立一個新的分支。

建議的程式碼是

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git switch -c <branch> main
git switch -c <branch> main
git switch -c <branch> main

我很高興,所以我執行命令並…

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
(eval):1: no such file or directory: branch
(eval):1: no such file or directory: branch
(eval):1: no such file or directory: branch

等等,什麼?啊,我忘了把 <branch> 換成實際的分支名稱🤦‍♂️。

這完全是我的錯,但幸運的是沒有發生什麼壞事,我修改了查詢並設定了正確的名稱。

潛在的有害例子

然而,在視訊的後面,我試圖移動和刪除提交,第一個建議是:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git reset --hard HEAD~1
git reset --hard HEAD~1
git reset --hard HEAD~1

想象一下,在不瞭解它的作用的情況下執行它……好吧,當然,用 reflog 你可以恢復丟失的提交,但如果你不知道,你可能會因為剛剛丟失的所有修改而感到恐慌。這似乎不是一個很酷的情況。

實際上,在寫這篇文章的時候,我意識到我可以在視訊中直接問這個問題:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git? recover the last hard reset commit
git? recover the last hard reset commit
git? recover the last hard reset commit

我現在做了,第一個建議是:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
──────────────────── Command ────────────────────
git reflog
git reset --hard HEAD@{1}
────────────────── Explanation ──────────────────
○ git reflog lists all commits that are no longer referenced by any branch.
○ git reset resets the current branch to a previous commit.
◆ --hard means that we also discard any changes made to the files in the working directory.
◆ HEAD@{1} specifies that we reset to the commit one before the current one.
──────────────────── Command ──────────────────── git reflog git reset --hard HEAD@{1} ────────────────── Explanation ────────────────── ○ git reflog lists all commits that are no longer referenced by any branch. ○ git reset resets the current branch to a previous commit. ◆ --hard means that we also discard any changes made to the files in the working directory. ◆ HEAD@{1} specifies that we reset to the commit one before the current one.
 ──────────────────── Command ────────────────────
git reflog
git reset --hard HEAD@{1}
────────────────── Explanation ──────────────────
○ git reflog lists all commits that are no longer referenced by any branch.
○ git reset resets the current branch to a previous commit.
◆ --hard means that we also discard any changes made to the files in the working directory.
◆ HEAD@{1} specifies that we reset to the commit one before the current one.

如果你只是不記得語法,這很好,但如果你不確定你在做什麼……想象一下,被人工智慧告知要恢復硬重置,你需要再做一次硬重置。那不是很嚇人嗎?讓我知道你的想法!

有趣的事實

當我開始錄製視訊時,我並沒有意識到我開啟了Copilot Voice。在某些時候,我說了這樣的話:

I’m on a branch called copilot-x-test, but is it correct?

(我在一個名為copilot-x-test的分支上,但它是正確的嗎?)

一秒鐘後,我聽到一個聲音從我的揚聲器裡傳出來:

It depends on the task. You should make sure that the task is valid and reliable before taking it

(這取決於任務的情況。在接受任務之前,你應該確保該任務是有效和可靠的。)

啊,是Copilot的聲音!

完整Demo

總之,這裡有完整的視訊,我在那裡玩Copilot X CLI,詢問 git 命令,並給你我對AI生成的建議的個人想法。

評論留言