我錯誤地洗掉了我實際上只想移動到另一個目錄的檔案。我也提交并推送了這個更改,因此這些檔案被視為已洗掉。有沒有辦法在之后將這些檔案移動到目錄中并使它們被視為“已移動”?
這將有助于保持 git 歷史記錄干凈。
提前致謝。
uj5u.com熱心網友回復:
假設:
- 您的分支未共享,這可讓您重寫其歷史記錄
- 你想避免這個“錯誤”留在歷史中,就像你第一次做對一樣
- “壞”提交是您提交/推送的最后一個提交(即在此提交之后沒有要保留的提交)
那么你可以:
# restore your files in the working tree
git restore --source=HEAD^ -- path/to/file1 path/to/file2 path/to/dir/*
# at this point, move the files where you want them to be
# then record them into index
git add .
# and edit last (bad) commit to record the move instead of the deletion
git commit --amend
# finally, push to remote for the new branch history to replace the old one
git push --force
uj5u.com熱心網友回復:
您可以還原更改:
git revert HEAD
然后,移動您的檔案并再次提交。考慮到 git 僅在 renameLimit 足夠高時才考慮移動檔案(https://git-scm.com/docs/merge-config)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/361019.html
標籤:混帐
