我剛剛對大約 4 個檔案進行了一些更改。將此提交發送到遠程后,我注意到此提交中包含了幾個額外的檔案。我怎樣才能
- 確保遠程不包含這些檔案中的更改。
- 確保生產服務器也不包含這些檔案(我已經在那里做了拉)
- 在我的本地作業樹中對這兩個檔案進行原始更改。
換句話說,就這些檔案而言,我想還原更改。
萬一這很重要,這是最新的提交。這個之后就沒有了。此外,這些是新創建的檔案,而不是正在更改的檔案。
編輯:
當我這樣做時git show,我可以看到我在提交中真正想要的檔案具有以下內容:
diff --git a/mysite/apps/common/models.py b/mysite/apps/common/models.py
index 9d86707..1a53b94 100755
--- a/mysite/apps/common/models.py
b/mysite/apps/common/models.py
而以某種方式錯誤包含的檔案有
diff --git a/mysite/apps/payment/migrations/0011_auto_20221006_1850.py b/mysite/apps/payment/migrations/0011_auto_20221006_1850.py
new file mode 100644
index 0000000..26320ba
--- /dev/null
b/mysite/apps/payment/migrations/0011_auto_20221006_1850.py
哪兒來的呢?
uj5u.com熱心網友回復:
不要通過要求將其保留在您的作業樹中而使其過于復雜。如果您進行還原(并在作業樹上丟失它)并推送以使其在您現在需要的地方得到糾正),那么您可以了解如何以您想要的方式將其恢復,完成(在還原之后) ) 和:
git checkout HEAD~ -- file1 file2
然后你可以用正確的提交資訊、正確的檔案和東西來提交它。
順便說一句,這不是你要求的不能完成......它可以完成,但我不明白你為什么要在產品已經投入使用時那樣做。
uj5u.com熱心網友回復:
出色地!如果您不想在遠程/生產服務器中,則不能將它們保留在提交中。如果您認為有一些檔案被錯誤地添加到您的上次提交中,那么您可以通過以下操作恢復到上次暫存狀態:
git reset --soft HEAD^
這將恢復您的上一次提交并將您的頭移到上一次提交,同時將所有檔案保持在暫存狀態。從那里您可以洗掉不需要的檔案git reset <file>。
uj5u.com熱心網友回復:
好吧,讓我們試著回答你的問題:
1. Make sure that the remote does not contain changes in these files.
2. Make sure that the production server also does not contain these files (I already did a pull there)
3. Have the original changes to these two files in my local working tree.
確保遠程不包含這些檔案中的更改
我不知道你的 SCM 供應商。如果您有 UI 服務,只需打開提交的鏈接并瀏覽檔案。如果您有權訪問遠程服務器,則可以:
ssh me@otherhost "cd repo && git log -n 10"
OR
ssh me@otherhost "cd repo && git show --pretty='' --name-only <commit>"
無需克隆即可在 git 存盤庫中瀏覽和顯示檔案
確保生產服務器也不包含這些檔案(我已經在那里做了拉)
您還可以連接到遠程生產服務器并找到所需的提交
git log --oneline --decorate --oneline --graph <branch>
如果您知道生產服務器上的提交哈希,則可以使用 follow
git show --pretty="" --name-only <commit hash>
獲取已更改檔案的串列
在我的本地作業樹中對這兩個檔案進行原始更改
因此,如果您的更改已發布(已提交)并且您沒有其他本地更改(而不是 git stash then 和 git stash list, git stash apply),您只需將本地 HEAD 重置為先前的提交(父)。
git reset --hard HEAD~ #if you didn't create any commits
# If you made some commits after publishing
# You should to rewrite linear history of branch
# Or make revert commit
# Case with rewriting history of your branch, let's name your branch as devel
1. find your published commit, let's name it as `git tag unstable <unstable_published_commit>`
2. Move temp_devel to parent of an unstable - `git branch -f temp_develop unstable~`
3. Checkout on temp_devel - `git checkout temp_devel`
4. "Pull" your changes from unstable commit - `git cherry-pick -n <unstable_commit>` and `git status` and remove unwanted files
5. git commit -m 'Your message'
6. Will be created a new commit with your two files
7. Rewrite history of `devel`, `git rebase -i HEAD devel`
8. You are in an interactive mode right now
9. You can remove or edit some of commits, read an instruction
10. `:wq` in `vim` to save and close your file
11. If rebase will be successful you can publish your `devel` branch with correct commit with two files. Otherwise just run - `git rebase --abort` to return everything as it was.
if you know that you doing at 8 step, than use git rebase --continue to continue your rebase state
它會洗掉您的本地更改和索引更改(小心,使用 git status 確保)
您還可以使用 .gitignore 檔案存盤在將更改添加到索引階段時要忽略的檔案或目錄串列。
如果您需要帶有有效負載資料的幾個檔案,您可以使用 git cherry-picn -n <published_commit_hash> 獲取相同的更改并使用 git checkout -- filename 或 git reset --filename 從索引階段排除不需要的檔案,查看 git status幫助資訊
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/518328.html
標籤:混帐
