Reputation: 692
I apologize in advance for asking this question as it has been asked a million times already.
I need to modify the git history of my project, the commit history currently looks like this:
[E] <- [D] <- [C] <- [B] <- [A]
Where: A: Added some code, B: Added some code & added some data, C: Restructured project, D: Removed all data, E: Added some code
The problem was that at commit C our project group was notified that data had to be stored locally and not publicly on git. I am not very experienced with git so the first thing I did was to remove the data. But that did not do much since the data could still be accessed in history. How do I fix the problem so that the history looks like this:
[E] <- [C] <- [B] <- [A]
Where: A: Added some code, B: Added some code, C: Restructured project (Without any references to data) E: Added some code
Upvotes: 0
Views: 213
Reputation: 706
You can do it with these commands:
# Rebase from C commit in interactive mode...
git rebase -i C
# Then remove the D commit line in the editor, save and quit.
# You can edit commit messages by using "edit" option for
# concerned commits.
# Resolve conflicts if needed and finish rebasing.
OR (without commit message editing):
# Rebase from C: Pick E history but exclude D history
git rebase --onto C D E
Then you will have to push force the modification (with all troubles that it can lead to...).
# --force-with-lease means:
# "If anybody already pushed after the last known origin/<branch> sha1,
# The push force command will be aborted (avoids to loose newers pushes
# from your friends...).
git push --force-with-lease origin <branch>
Upvotes: 1
Reputation: 719
Here is a way to remove specific commit if from history
git rebase --onto commit-id commit-id HEAD
You can use below command to remove commit "D" from history
git rebase --onto D E HEAD
Upvotes: 4