-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Extend commit panel with branch operations (switch/rename/delete) #4115
Comments
I'm not sure what you mean by "log view", that's not standard lazygit terminology as far as I can tell. Are you talking about the Commits panel (panel 4), or about the commits view that you get by pressing enter on a branch in the Branches panel (panel 3), or something else? Either way, I don't quite see how the UX would work for what you are suggesting. The standard paradigm for lazygit to operate on things (in order to rename or delete them) is to have a list of these things (e.g. in the Branches panel), select one, and then invoke the command that operates on the selected thing. I don't see how you would do that if the list of these things is not visible because you are in some other panel. Do you have more concrete suggestions for how exactly your proposed operations would work? Finally, it might help if you describe some of your complex workflows more concretely (maybe with screenshots), I don't really think I understand what it is that you are missing. |
First I updated the issue to align with Lazygit terminology. For me it is the standard view on the git log, that's why I reached for the term "log view". But your right, we should stick to the established terms of the project. There are two options to implement this, one, which needs more keybindings, the other would be a bit more cumbersome to work with, but I would be fine with both of them. Option 1:
When there is only one branch on the selected commit, the command is applied immediately, otherwise we could have a select box for the available branches to resolve (similar to what we have with e.g. setting upstream branches). If no branch is available, we could show an error. I always liked the metaphor of post-its attached to commits for branches and tags in git and I would like to move my post-its around looking at the commit graph. This kind of workflow I usually do when experimenting locally with code. Then I use my Git like a tree of local snapshots of my work. Before I merge something into long time history, I need to consolidate and clean up and while I like squashes and fixups, sometimes it get's a bit more complicated. Option 2: I was formerly a poweruser of SmartGit, where they have this feature - and I used it a lot. But I love my command line, my TUIs and my vim motions, so when I discovered lazygit I almost abandoned SmartGit. I am also teaching Git to colleagues and it helps newcomers a lot in understanding what actually happens when doing branch operations visually on the commit graph. |
Oh wait, you are talking about the Commits panel when the "git.log.showWholeGraph" option is on, is that true? It always makes me nervous when people use this option, because it is so broken. We have tons of code all over the lazygit codebase that assumes all entries in the Commits panel belong to the current branch; #3608 has some examples, but there are probably many more. I wish we didn't have that option, at least as long as we didn't fix all those issues. (But then, even without the showWholeGraph option, the commands you are proposing to add can still be useful in a stacked branches workflow.) Anyway, thanks for the detailed explanation, it makes a lot more sense to me now. My initial reaction was that I don't like adding more keybindings to the Commits panel because it has so many already, but actually some of them could be folded into the existing ones, so it wouldn't be so bad. Let's see in detail:
The nice thing about this is that these don't have to be done all at once; they could be added one by one, the most important ones first. Are you interested in working on (some of) this? |
Thanks for the detailed answer. And yes, I am speaking about the showWholeGraph feature. If I would have to put priorities onto the listed operations, the list would look like this:
|
Makes sense to me, and we could easily start by making PRs for the first two, they are the easiest probably. You didn't answer my last question though. :) |
To answer your last question: Another rabbit hole I can dive into and an opportunity to learn Go ... actually, if you can give me some entry points into the code base and also some advice, what I have to consider in terms of code style and pattern, I would be happy to contribute. I cannot make promises, but having another project over the Christmas holidays which makes me more productive in the new year sounds tempting. 🤓 Edit: I just forked the repo and started to look into the contribution guidelines. But if you already can give me more direct hints where I need to look into the codebase to implement one of the listed operations, I would appreciate that. 👍 |
Cool. I recommend to start by reading Then, the code to checkout a commit is here. Note that BasicCommitsController is not only for the Commits panel; it is also used for the subCommits view (e.g. when you press enter on a branch or tag) and for the reflog view, but there's no reason not to offer the same functionality there, so why not. To find the branches that point to the selected commit, loop over the branches in the model (no need to make a git call). Let me know if you get stuck on anything. |
Currently I struggle to understand how to access the branches from the |
Controllers have a Development tip: the go language server is very good at auto-completing incomplete call chains, so if you suspect the model is available somehow, you can start typing |
Ok, I have a first basic version of the switch-branch-feature working. I want to polish it a bit though. Particularly I want to add the possibility to checkout also remote branches. But I don't know, how to correlate a remote branch to it's current commit hash, because it doesn't have a And in general, would you prefer to continue the discussion in a draft PR? Edit: I decided to create a first PR #4117 and leave the remote branches for later improvement. |
I was wondering about remote branches as well, but wasn't sure how important that is. Thinking about it, it could actually be quite useful, for example if a coworker pushes a stack of branches, and I check out the top branch of the stack and want to easily check out the other ones as well from there. It's funny that remote branches don't have a Hash field, it seems we never needed it so far. It should be quite easy to add though. We simply add Note, however, that adding remote branches to the feature is not trivial. You need to check whether there is already a local branch that has this remote branch as an upstream; however, the local branch needn't necessarily have the same name as the remote branch, and of course it needn't point at the same commit. I think this is complex enough that it would be best done in a separate PR. |
- **PR Description** When the user checks out a commit which has a local branch ref attached to it, they can select between checking out the branch or checking out the commit as detached head. If no local branch is attached to the commit, the behavior is like before: They are asked to confirm, if they want to checkout the commit as detached head. Requested in #4115. Note: I tried also to consider remote branches, but because I wasn't able to correlate remote branches to their commits, I deferred it and leave it open for later improvement.
Is your feature request related to a problem? Please describe.
Lazygit's commit panel provides a clear visualization of the git graph, which is particularly helpful when working with complex branch structures.
During intensive branch cleanup sessions (involving rebasing and cherry-picking), I frequently need to switch between the commit panel and branch view to manage branches. This interrupts the workflow as I lose sight of the graph structure momentarily and need to keep branch names in mind while navigating between views. This becomes particularly challenging when working with multiple branches that need reorganizing.
Describe the solution you'd like
Since Lazygit already supports creating new branches from the commit panel, it would be helpful to have other branch operations available there as well. Specifically, being able to:
Having these operations available directly where we can see the full branch structure would streamline complex git workflows.
Describe alternatives you've considered
Currently, I work with the standard approach of noting the branch name from the commit panel, switching to the branch view, finding the branch again, and performing the operation there. While this works, it interrupts the natural flow of working with the git graph, especially during intensive cleanup sessions.
Additional context
This enhancement would complement Lazygit's existing visualization capabilities. By bringing branch management directly to where the branches are visualized, it would make complex git workflows more efficient.
The text was updated successfully, but these errors were encountered: