簡體   English   中英

Git rebase 在每次提交之前停止,然后編輯和 rebase --continue

[英]Git rebase to stop just before each commit to then edit and rebase --continue

我注意到當我變基並發生合並沖突時,它具有當前提交的分階段更改,因此很容易找到提交中所做的並更改它,但是您也可以只執行 'git rebase --continue ' 並且它將使用與以前相同的提交消息應用更改。

有沒有辦法強制針對特定提交或所有提交發生這種情況,以便我可以輕松地重新設置和編輯我之前所做的更改以處理我重新設置的更改? 似乎這比僅在所有提交上設置編輯然后執行“git reset --soft HEAD~”要容易得多,這樣更改是可見的,我可以檢查它們對新 HEAD、編輯和然后不得不做'git commit -m“message”'。

我的用例是我正在使用的存儲庫已對其文件結構進行了大量重構,git 無法進行適當的更改,但表示合並成功。

謝謝!

我認為您正在尋找的是交互式變基和重寫 git 歷史。 它可以讓你壓縮提交以及更改提交消息。

git rebase -i branch # <branch> should be the parent branch i.e. develop/master

重寫 git 歷史

# for instance
>>> git rebase -i branch
pick 8705209 first
edit 7979797 second # Use edit wherever you want to view and edit commit
squash 9793757 third # Use squash to squash commits into the previous one.

只需在git rebase --continue git commit --amend執行 git commit --amend 。

或者 - 使用git-cherry-pick --no-commit commit1..commitN

強制這種情況發生在特定的提交上

使用git rebase -i HEAD~~~啟動交互式變基。

這將打開一個帶有提交列表的編輯器:

pick 1234567 fix stuff
pick 789abcd new features
pick 0102030 break everything

在要edit的提交(或提交)上更改要編輯的pick 保存並退出編輯器。

然后,git 會一一帶你回到這些提交,你可以編輯它們。 我認為您缺少的是,此時,您可以使用git diff --cached查看暫存的差異。

編輯完每一項后,使用git rebase --continue繼續。

這不是一個真正的答案,但我最初目標的替代解決方案現在只是進行變基,然后使用lazygit編輯提交。

暫無
暫無

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

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