lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Does deleting the newest commit in lazygit is the same as git reset --hard HEAD~1?

Open finviman opened this issue 2 years ago • 6 comments

Topic the version is 0.37 i have a git repo commit log like this, it's a tig show in nigthtly branch. I use tig snapshot because its log graph is clear. image there is a master branch , i checkout nightly and feature1 branch from it. Then make a commit on nightly, make two commits on feature1, at last merge feature1 to nightly, no conflicts.

All the operations below is happened in nightly branch. Then i just need to delete the top merge commit. so I delete it in lazygit by press d in commits pane. but the result is so confused. image It deletes the merge commit and also the commit I did in nightly branch and cherry-pick 2 commits of feature1 to nightly. But I think it should only delete the merge commit as git reset --hard HEAD~1 does.

Your thoughts If it's not a bug , what the exactly delete commit means in lazygit?

finviman avatar Feb 09 '23 04:02 finviman

Checking the log shows the following happens when deleting a commit:

git rebase --interactive --autostash --keep-empty <ref-before-the-commit-for-deletion>

And then the commit is marked as drop and the rebase continues.

I'm guessing the issue here is that rebasing over merge commits is wonky, so I'm not really sure what git does in such situations.

You could use g in the commits panel which lets you pick a type of reset you want to execute.

Sorta unrelated - why do you merge and then delete the merge commit, isn't that the same as rebasing?

mark2185 avatar Feb 09 '23 05:02 mark2185

thank you, i noticed the command outputed in "Command Log" pane. the g command is really what i need. But all of these is counter-intuitive. 1F4221F5

finviman avatar Feb 09 '23 05:02 finviman

Well, d should stand for drop actually, yeah.

mark2185 avatar Feb 09 '23 06:02 mark2185

More, I execute the command in command log output manually, it will rebase interactively, means i can decide to drop or pick the previous commits in nightly, but lazygit drop them directly. Anyway it's a weird and dangerous operation in merge commits.

finviman avatar Feb 09 '23 06:02 finviman

Well, rebasing over merge commits is somewhat unintuitive in general, so I do get the confusion :)

Also, why do you merge and then delete the merge commit, are you sure you're not looking for a rebase?

mark2185 avatar Feb 09 '23 06:02 mark2185

not rebase for sure. I just test the merge request function in gitlab, wishing to get merge commit info through gitlab graphql api but after many times merge and delete merge and merge again , I think gitlab api has a bug of unable to give merge commit info .

finviman avatar Feb 09 '23 06:02 finviman