The commit history looks like this: Commit1 CommitFIX Commit2 Commit3
How to remove CommitFIX history so that its edits are in Commit1?
The commit history looks like this: Commit1 CommitFIX Commit2 Commit3
How to remove CommitFIX history so that its edits are in Commit1?
To solve this kind of problem, use the interactive version of the git rebase .
Switch to Commit3
git checkout Commit3 Run interactive git rebase
git rebase -i HEAD~4 The environment for editing the history change script will start. Use squash to merge commits.
pick Commit1 squash CommitFIX pick Commit2 pick Commit3 # Rebase 710f0f8..a5f4a0d onto 710f0f8 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out Save the file and exit it to run the script.
Check history, it will be successfully changed.
PS Be careful when using this technique, because git rebase essentially creates new commits. Do not change the history if you have already sent changes to the remote repository.
Source: https://ru.stackoverflow.com/questions/791661/
All Articles