Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop commit #174

Closed
borekb opened this issue Sep 5, 2019 · 6 comments
Closed

Drop commit #174

borekb opened this issue Sep 5, 2019 · 6 comments
Assignees
Labels
feature request Feature request
Milestone

Comments

@borekb
Copy link

borekb commented Sep 5, 2019

Describe the feature that you'd like
I'd like to right-click a commit in Git Graph and select a Drop Commit command, which would basically run a rebase, omitting the commit.

Additional context (optional)
Sometimes, I work in a feature branch and commit to it even things that are not strictly related to the it (so that I don't lose the flow). After I'm done, I use cherry-pick to copy the commits to a new branch but am left with the original commits in the original branch.

At this point, I need to run git rebase -i HEAD~5 or similar and delete the commits I no longer need.

It would be great if I could do this directly in the UI. It would be a sibling feature to Revert....

@borekb borekb added the feature request Feature request label Sep 5, 2019
@mhutchie
Copy link
Owner

mhutchie commented Sep 5, 2019

Thanks for raising this feature request, this would definitely be useful to have in the Commit context menu.

This page suggests the command the extension should run to drop a commit is git rebase -p --onto SHA^ SHA. Although there does appear to be some issues with this command.

From reading the Git documentation here, the argument -p is now depreciated and has been replaced with --rebase-merges.

From what I can see, the command should now be git rebase --rebase-merges --onto SHA^ SHA (I haven’t tested it yet). Please let me know if you’re aware of a better command to drop a commit (using its commit hash).

@borekb
Copy link
Author

borekb commented Sep 6, 2019

I didn't even think --onto was necessary but didn't properly play with it. Here's how I would naively / manually do it:

  1. Count which commit I want to drop. For example, let's say I want to drop the fourth most recent commit in my feature branch so the number would be 4.
  2. I'd run git rebase -i HEAD~4.
  3. I'd set the rebase operation to drop next to the commit I want to get rid of.
  4. I'd save the todo and close the file.

I'm going to read the git-rebase docs to understand this better, thanks for considering this feature request so carefully.

@mhutchie mhutchie added this to the v1.15.0 milestone Sep 9, 2019
@mhutchie
Copy link
Owner

mhutchie commented Sep 9, 2019

This will be available in v1.15.0.

If you'd like to use it before the next release, you can download v1.15.0-beta.1, and install it following the instructions provided here.

@mhutchie mhutchie closed this as completed Sep 9, 2019
@MuathAmer
Copy link

I dropped a commit accidentally and need to undo this, is this possible in any way?

@mhutchie
Copy link
Owner

mhutchie commented Jun 2, 2021

Hi @MuathAmer,

In the Git Graph View’s Repository Settings Widget, you should be able to temporarily turn on “Include commits only mentioned by reflogs”. This should allow you to see the dropped commit, and then perform the required actions to include it back into your branch.

@MuathAmer
Copy link

@mhutchie
Very helpful and quick! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

3 participants