git-history(1) fixup broken with worktrees?
Hi,
Imagine this repoducer:
$ git init
$ echo Hello > README
$ git add .
$ git commit -m'initial commit'
$ git worktree add ../feature
$ echo world >> README
$ git add .
$ git history fixup HEAD
$ cd ../featureNow running git-status(1) in that other worktree gives me:
$ git status
On branch feature
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README
And:
$ git diff --staged
diff --git a/README b/README
index 65a56c3..e965047 100644
--- a/README
+++ b/README
@@ -1,2 +1 @@
Hello
-worldSo suddenly my other worktree is dirty? With staged changes? And I didn't even touch it.
Now the commit history is correct:
$ git log --graph --oneline --all
* 16ef548 (HEAD -> feature, main) initial commit
Signature · 2 lines
Cheers, Toon
Hi Toon
Quoted 35 lines · Toon Claes
Imagine this repoducer:
$ git init $ echo Hello > README $ git add . $ git commit -m'initial commit' $ git worktree add ../feature $ echo world >> README $ git add . $ git history fixup HEAD $ cd ../featureNow running git-status(1) in that other worktree gives me:
$ git statusOn branch feature
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: READMEAnd:
$ git diff --stageddiff --git a/README b/README index 65a56c3..e965047 100644 --- a/README +++ b/README @@ -1,2 +1 @@ Hello -world
Quoted 2 lines
So suddenly my other worktree is dirty? With staged changes? And I didn't even touch it.
I think what's happening is that the branch "feature" is updated because the commit it points to is rewritten, but the index and working copy in the work tree "feature" are not. Rebase's --update-refs option refuses to update branches that are checked out in other workers by default to avoid exactly this problem[1]. As you can see in that thread there was some discussion about updating the index and working copy when the work tree is clean instead. I think that is a friendlier approach as it preserves the relationships between branches and avoids materializing changes in other worktrees.
On a related note, rebase refuses to rewrite a branch that is being rewritten by another rebase running in a different work tree. That's an important safety measure that I think the history command is missing.
Thanks
Phillip
[1] https://lore.kernel.org/git/[email protected]/
Quoted 8 lines
Now the commit history is correct:
$ git log --graph --oneline --all* 16ef548 (HEAD -> feature, main) initial commit
Quoted 3 lines · Phillip Wood
I think what's happening is that the branch "feature" is updated because the commit it points to is rewritten, but the index and working copy in the work tree "feature" are not.
Yeah, it's relatively easy to understand what goes wrong, the fix would be a bit more involved.
Quoted 3 lines
Rebase's --update-refs option refuses to update branches that are checked out in other workers by default to avoid exactly this problem[1].
Ah, thanks for finding this existing discussion, interesting.
Quoted 4 lines
As you can see in that thread there was some discussion about updating the index and working copy when the work tree is clean instead. I think that is a friendlier approach as it preserves the relationships between branches and avoids materializing changes in other worktrees.
Yeah, I agree it would be nice if git-history(1) would give it their "best-effort".
Quoted 3 lines
On a related note, rebase refuses to rewrite a branch that is being rewritten by another rebase running in a different work tree. That's an important safety measure that I think the history command is missing.
From [2] I've learned there are multiple ways a branch can be checked out. We have to take them all into account. It can be build on top of the changes in that patch.
[2]: https://lore.kernel.org/git/[email protected]
Signature · 2 lines
Cheers, Toon
Quoted 15 lines · Toon Claes
Quoted 3 lines · Phillip Wood
I think what's happening is that the branch "feature" is updated because the commit it points to is rewritten, but the index and working copy in the work tree "feature" are not.
Yeah, it's relatively easy to understand what goes wrong, the fix would be a bit more involved.
Quoted 3 lines
Rebase's --update-refs option refuses to update branches that are checked out in other workers by default to avoid exactly this problem[1].
Ah, thanks for finding this existing discussion, interesting.
Quoted 7 lines
Quoted 4 lines
As you can see in that thread there was some discussion about updating the index and working copy when the work tree is clean instead. I think that is a friendlier approach as it preserves the relationships between branches and avoids materializing changes in other worktrees.
Yeah, I agree it would be nice if git-history(1) would give it their "best-effort".
Sorry, I missed this thread for quite a while. In any case, I agree that we should probably do the same for git-history(1) as well and refuse updating any branches that are currently checked out in another worktree.
I've created an issue [1] for this scheduled for the next release cycle. Happy if anybody else beats us to it though. Thanks!
Patrick
Hi Patrick,
Quoted 2 lines
I've created an issue [1] for this scheduled for the next release cycle. Happy if anybody else beats us to it though.
It seems nobody has picked this up. Can I send a patch so that git history refuses to update a branch that is checked out in another worktree or is getting rebased when the update would change its tree? This should cover Nikita's report.
Thanks,
Aniket
Quoted 9 lines · Aniket Gupta
Hi Patrick,
Quoted 2 lines
I've created an issue [1] for this scheduled for the next release cycle. Happy if anybody else beats us to it though.
It seems nobody has picked this up. Can I send a patch so that git history refuses to update a branch that is checked out in another worktree or is getting rebased when the update would change its tree? This should cover Nikita's report.
At GitLab we currently don't have anyone planned to work on this. So yes, you're welcome to pick this up. Feel free to Cc me for review.
Signature · 2 lines
Laters, Toon