最終,到目前為止,我想要一種干凈的方式來回傳core.bare false到任何分支的緊湊(例如,裸)repo 準備簽出(好的,對于迂腐的:在附加之后)。我已經閱讀了如何將普通 Git 存盤庫轉換為裸存盤庫的最佳答案?. 使用clone評論中提到的松散配置條目,下面是嘗試使用接受的答案后的問題。也許有一個簡單的微不足道的解決方法,這就是為什么我在評論中找不到它的原因。
TL; 博士
我試圖理解與裸 git 存盤庫相關的資訊。
- 克隆所有分支: 如何在 Git 中克隆所有遠程分支?:
執行并有效:
git clone --mirror https://github.com/vmatare/thinkfan.git path/to/dest/.git
cd path/to/dest
git config --bool core.bare false
git checkout master # checkout devel also works with freshly cloned repo
Man git-clone:
--mirror Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
現在在git checkout anybranch我.git只得到檔案夾之前:
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
...
“已洗掉”輸出為綠色。即洗掉在索引中并準備提交(根據輸出并在https://unix.stackexchange.com/questions/458354/git-status-coloring-deleted-files 中解釋)。
- 轉換為裸機:https : //stackoverflow.com/a/2200662/14557599
執行:
cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true
即洗掉所有除外.git并將core.bare配置值更改為true.
在那之后
git config --bool core.bare false
順便說一句
git config --bool core.bare true
git config --bool core.bare false
等于沒有或某些內部狀態發生了變化?無論如何,兩者都意味著我遵循了已接受的答案來制作裸回購。并且這樣做clone --mirror我還制作了裸回購。但現在“已洗掉”是紅色的,輸出是“未暫存的更改提交”:
git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
...
no changes added to commit (use "git add" and/or "git commit -a")
為什么最初克隆的 repo 然后再次轉換為裸 repo 之間存在如此大的差異?
我試圖閱讀答案的評論以制作裸回購,但沒有注意到提到該問題。
如果現在我這樣做了git add *,那么顯然狀態與我剛剛克隆時的狀態相同--mirror:
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
但結帳后比不起作用。
$ git checkout devel
error: Your local changes to the following files would be overwritten by checkout:
CMakeLists.txt
Please commit your changes or stash them before you switch branches.
Aborting
clone --mirror除了.git查看為什么checkout在第一種情況下有效但在第二種情況下無效之外,如何在洗掉所有內容之后立即查看回購“狀態”之間的區別?
uj5u.com熱心網友回復:
改變core.bare來自true于false不支持。不要指望任何事情都會奏效。
如果您了解 Git 的內部結構,就可以讓它發揮作用。(其他 SO 答案中的說明至少部分是由知道如何使其作業的人撰寫的。)但是,您知道為什么不將其與--mirror.
運行后git checkout,您在裸存盤庫中創建了一個索引(又名暫存區)。您需要洗掉索引 ( rm .git/index)。這將解決問題,至少是暫時的。但是不要像這樣將裸機轉換為非裸機并回傳:它不受支持。
考慮將裸存盤庫保留為裸:您可以使用git archive從裸存盤庫中獲取您想要的任何提交。請參閱該git archive檔案的詳細資訊。該git branch和git log命令(以及其他許多)在純倉庫的作業,讓你找到哈希ID來供應git archive。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378108.html
