mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-13 20:27:29 -05:00
1.2 KiB
1.2 KiB
title | date | draft | tags | medium_enabled | |
---|---|---|---|---|---|
How to Drop Commits in Git | 2020-05-26T00:48:37-04:00 | false |
|
true |
Even though it is not recommended to rewrite history in Git, it can be useful to drop certain commits from a pull request. The easiest way I've found to achieve this is with git rebase
. To look back at the last 5 commits
git rebase -i HEAD~5
This will produce a view like the following:
pick bda8e1d Follow better coding standards
pick ed62936 Bad Commit
pick 5b89e82 Refactoring to make more sense
pick 2941129 Delete Everything
pick 04d6558 New Feature
You can then change the commits you want to remove from pick
to drop
.
pick bda8e1d Follow better coding standards
drop ed62936 Bad Commit
pick 5b89e82 Refactoring to make more sense
drop 2941129 Delete Everything
pick 04d6558 New Feature
Once you exit out, the two commits will be dropped.
Instead of analyzing the last 5 commits, you can also analyze the commits made after branching out. Let's say we're on a feature branch based on the development
branch.
git rebase -i development
From there you would get the same pick/drop
screen as before.