簡體   English   中英

Git:簽出以前的提交並在該提交創建的分支中工作

[英]Git: Checkout a previous commit and work in the branch created by that commit

我正在建立一個網站,它在本地構建良好,但不在服務器上。 服務器從 Github 中提取代碼,因此我必須將以前的提交上傳到我的 Github 以查看服務器在哪個提交上失敗。

我試過了

git checkout 1111111111111111111111111111111111

這讓我陷入了一個分離的頭 state,當我嘗試提交時,我得到了

HEAD detached at 1111111
Revert currently in progress.
  (run "git revert --continue" to continue)
  (use "git revert --skip" to skip this patch)
  (use "git revert --abort" to cancel the revert operation)

nothing to commit, working tree clean
Branch 'master' set up to track remote branch 'master' from 'origin'.

於是我checkout master脫離了超然的腦袋再試了

git checkout -b 1111111111111111111111111111111111

並得到

Switched to a new branch 1111111111111111111111111111111111

但是當我建立我的網站時,它仍然在 master 上構建版本所以我嘗試

git switch 1111111111111111111111111111111111

並得到

warning: refname '1111111111111111111111111111111111111111' is ambiguous.
Git normally never creates a ref that ends with 40 hex characters
because it will be ignored when you just specify 40-hex. These refs
may be created by mistake. For example,

  git switch -c $br $(git rev-parse ...)

where "$br" is somehow empty and a 40-hex ref is created. Please
examine these refs and maybe delete them. Turn this message off by
running "git config advice.objectNameWarning false"
fatal: cannot switch branch while reverting
Consider "git revert --quit" or "git worktree add".

所以我嘗試這個沒有問題

git config advice.objectNameWarning false

然后我嘗試

git switch 1111111111111111111111111111111111
warning: refname '1111111111111111111111111111111111' is ambiguous.
fatal: cannot switch branch while reverting
Consider "git revert --quit" or "git worktree add".

而且我認為我仍在master分支中工作,visual studio代碼仍然說我在底部的master分支中

在此處輸入圖像描述

我什至沒有看到我的分支可用

在此處輸入圖像描述

當您使用 object ID 運行git checkout -b時,您創建了一個與 object ID 命名相同的新分支,因為-b之后的第一個參數是分支的名稱。 正如 Git 告訴你的那樣,創建這樣命名的分支並不是一個好主意。

首先,使用git branch -d (或git branch -D )刪除您創建的分支,並將您傳遞給git checkout -b的 40 個字符的十六進制名稱傳遞給它

完成此操作后,從修訂版創建新命名分支的最佳方法是運行git checkout -b NEW-BRANCH-NAME REVISION 請注意,修訂版位於新分支名稱之后 然后,您可以將該分支推送到服務器以對其進行測試並在那里構建它。 如果您想在下一次測試中重用相同的分支,請使用git checkout -B而不是git checkout -b ,這將覆蓋分支,然后強制將分支推送到服務器。

可能您的構建過程僅適用於master ,在這種情況下,您必須強制推動該分支。 希望如果是這種情況,您將修復您的構建過程,以便它首先從分支構建,這是更好的選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM