Edit a commit and bring all the changes back to unstaged #4461
-
I'm new to Lazygit and coming from Tower. There, I can right click a commit and click edit. It will then bring me back to before this commit, with all the changes from the commit being in my working copy as changed files. I can then stage some files, and commit them. The commit is prefilled with the original commit (that I'm editing). But if I make changes, it will use that. The remaining changes in my working copy I can commit again, or discard. Basically, with editing you can split a commit or rework a commit message or the files associated to the commit. But how can this be done with Lazygit? If I edit a commit, it brings me back to AFTER the commit, with the changes being committed already. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Tower's approach seems to be inspired by how you would have to do this with command-line git, where you perform an interactive rebase and then This is an arcane workflow that we shouldn't try to follow. Lazygit has much better tools for this; look into custom patches. For splitting a commit, you press enter on the commit to see its files, "stage" the ones that you want to split out (you can also stage individual hunks by pressing enter on files), then bring up the custom patch menu (ctrl-p) and choose "Move patch into new commit". No interactive rebase involved. The custom patch feature also lets you move parts of a commit to a different commit, or drop changes from a commit, and other useful things.
This is even simpler of course, no custom patches needed for this. Reworking a commit message is easy by selecting the commit and pressing |
Beta Was this translation helpful? Give feedback.
Select A, hit
e
. Run your formatter; hit shift-A to amend, and continue the rebase. You are likely to get conflicts in B and/or C; resolve them using "incoming" for all. (Now this last thing is something that's not very convenient in lazygit yet, we might improve this at some point).