jesseduffield / jesseduffield/lazygit
Rewording commit after external branch switch loses commits
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
If I switch branches from the command line while lazygit is open, then return to lazygit and reword a commit, lazygit doesn't realize that I've switched branches. The commit gets reworded OK, but the end result is that the new branch gets hard-reset to point to the reworded commit (which was from the other branch). The commits that were on the other branch are orphaned. So to get them back generally requires looking in the reflog.
**To Reproduce**
Open lazygit in one terminal while we're on a branch (in this case, "main").
In a separate terminal, confirm the state of our two branches - "main" and "side-project", then switch to the "side-project" branch:
```
>>> git log main
commit 3ad567a960729a963a4ac6ae6098cd51baba2b0b (HEAD -> main)
Added c.txt
commit 6c69d3e272aa90be402c1c21f4f60031dccab300
Added a
>>> git log side-project
commit 460481cf893ef501d3da847e277d7da257471db4 (side-project)
Added b.txt
commit 6c69d3e272aa90be402c1c21f4f60031dccab300
Added a
>>> git co side-project
Switched to branch 'side-project'
```
Back in lazygit, switch to the commits panel (4) then reword (R), enter a new commit description for the commit "Added c.txt" -> "Added c.txt (reworded").
Return to the separate terminal to see what happened:
```
>>> git log side-project
commit ecee69ce24f8bc0215633cc2b2b46d4ae679b39f (HEAD -> side-project)
Added c.txt (reworded)
commit 6c69d3e272aa90be402c1c21f4f60031dccab300
Added a
>>> git log main
commit 3ad567a960729a963a4ac6ae6098cd51baba2b0b (main)
Added c.txt
commit 6c69d3e272aa90be402c1c21f4f60031dccab300
Added a
```
Both branches now have commits that add "c.txt". The commit that adds "b.txt" is now not on either branch.
**Expected behavior**
A few possibilities come to mind:
* If lazygit thinks we're on main (when we're not) and the commit it's rewording is on main, it could reset main to point to the reworded commit.
* It could report an error and say that an external branch change was detected.
* Lazygit could switch back to the branch that it thought it was on before doing the reword.
**Desktop**
- OS: Linux (Debian based)
- Lazygit Version: 0.31.3
**Workarounds**
* Always use lazygit to switch branches.
* Exit and reopen lazygit whenever you think lazygit has the wrong idea of which branch we're on.
Contributor guide
Assessment
This issue has not been assessed yet.