我有一個 2014 年的資料集,其中包括錯誤報告和相應的修復提交。提交 SHA 有七位數長,我猜,在 2014 年,它足以唯一地識別提交。但是,在 2022 年,7 位 SHA 無法再唯一識別所有提交。
因此,我想知道是否可以克隆僅在 2014 年或之前提交的存盤庫,以便七位數的 SHA 足以唯一地識別所有提交。
uj5u.com熱心網友回復:
如果您只想在某個日期之前從一個分支克隆所有內容,請在最后一次提交時創建一個新分支,以包含在服務器上或通過推送本地分支。
之后,使用--branch your_created_branch簽出您創建的分支的--single-branch選項和僅克隆指向您指定的分支的歷史記錄的選項克隆存盤庫。
請注意,如果您在未來的任何時候嘗試獲取或拉取,您最終可能會將其他更新的提交和分支拉入本地存盤庫。
請參閱此處的 git clone 檔案。
uj5u.com熱心網友回復:
存盤庫克隆將為您提供該存盤庫的完整提交歷史記錄。所以這不是一個好主意。
- 您可以鍵入命令
git log,該命令將顯示有關所有先前提交的詳細資訊 - 您可以通過鍵入將狀態更改為特定/所需的提交
git checkout commit-hash。提交哈希將是您要移動的提交的唯一 ID。 - 要縮小提交串列,您也可以嘗試此命令
git log --since=2014-05-05 --until=2014-05-06。這將檢索日期之間的結果
uj5u.com熱心網友回復:
除了Jonathon S.'s answer,這是一個很好的方法來自動化他概述的所有限制,請注意現代 Git 將列出所有匹配的物件,給定一個簡短的哈希:
$ git rev-parse a123
error: short SHA1 a123 is ambiguous
hint: The candidates are:
hint: a1231de002 commit 2011-01-26 - tests: sanitize more git environment variables
hint: a123978771 commit 2009-04-23 - git-show-branch.txt: cleanup example description
hint: a123a47f40 commit 2018-08-28 - l10n: ru.po: update Russian translation
hint: a123b19eec commit 2015-08-24 - Merge 'kn/for-each-tag-branch' into kn/for-each-tag
hint: a12303cc5e tree
hint: a123f8cce3 tree
hint: a1230d7ead blob
a123
fatal: ambiguous argument 'a123': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
(我在 Git 本身的 Git 存盤庫的克隆中運行它),或者:
$ git rev-parse a123^{commit}
error: short SHA1 a123 is ambiguous
hint: The candidates are:
hint: a1231de002 commit 2011-01-26 - tests: sanitize more git environment variables
hint: a123978771 commit 2009-04-23 - git-show-branch.txt: cleanup example description
hint: a123a47f40 commit 2018-08-28 - l10n: ru.po: update Russian translation
hint: a123b19eec commit 2015-08-24 - Merge 'kn/for-each-tag-branch' into kn/for-each-tag
a123^{commit}
fatal: ambiguous argument 'a123^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
如果你不需要自動解決,你可以git rev-parse把所有的可能性都吐出來,挑出你認為正確的。如果您愿意,可以添加^{commit}限制器以減少匹配次數。
(請注意,提交的后面是提交日期和簡短的主題行,這使您的任務變得更加容易。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/431875.html
標籤:混帐
上一篇:使功能分支成為新的發展
