unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* git: how to restore a deleted worktree?
@ 2018-01-04 13:51 Stephen Leake
  2018-01-04 14:06 ` Noam Postavsky
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Stephen Leake @ 2018-01-04 13:51 UTC (permalink / raw)
  To: emacs-devel

I have the emacs-26 branch checked out in a worktree created by :

cd emacs/master
git worktree add -b emacs-26 ../emacs-26 origin/emacs-26

At some point, that worktree was in a confusing state, so I deleted it,
intending to do a fresh checkout. So I repeated the above command, but
it complained "branch emacs-26 already exists". So I dropped the '-b
emacs-26', and the command seemed to work.

However, 'git status' in the new worktree says "not on any branch", 
'git push' complains about fast-forward, and 'git pull' says not on a
branch.

How do I fix this?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 13:51 git: how to restore a deleted worktree? Stephen Leake
@ 2018-01-04 14:06 ` Noam Postavsky
  2018-01-04 22:04   ` Stephen Leake
  2018-01-04 14:07 ` Nathan Moreau
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Noam Postavsky @ 2018-01-04 14:06 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

On Thu, Jan 4, 2018 at 8:51 AM, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:

> At some point, that worktree was in a confusing state, so I deleted it,
> intending to do a fresh checkout. So I repeated the above command, but
> it complained "branch emacs-26 already exists".

You need 'git worktree prune' to make git remove the bookkeeping info
about that deleted worktree (possibly you have delete your new tree
first, not sure how pruning works when you've recreated a new worktree
in the same place).

git help worktree:

    When you are done with a linked working tree you can simply delete
    it. The working tree’s administrative files in the repository (see
    "DETAILS" below) will eventually be removed automatically (see
    gc.worktreePruneExpire in git-config[1]), or you can run git
    worktree prune in the main or any linked working tree to clean up
    any stale administrative files.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 13:51 git: how to restore a deleted worktree? Stephen Leake
  2018-01-04 14:06 ` Noam Postavsky
@ 2018-01-04 14:07 ` Nathan Moreau
  2018-01-04 22:07   ` Stephen Leake
  2018-01-04 14:49 ` Andreas Schwab
  2018-01-04 18:29 ` Stefan Monnier
  3 siblings, 1 reply; 10+ messages in thread
From: Nathan Moreau @ 2018-01-04 14:07 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

It's not clear what you did when you `deleted' the worktree. The
proper way to cleanup worktrees is
+ first to remove the associated branch (emacs-26)
+ then `git worktree prune'.

This is probably what you need to do to get back to a clean state in
your case, before going to `git worktree add....' again.
If you just run the prune command, git won't prune anything as the
branch still exists.

On 4 January 2018 at 14:51, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:
> I have the emacs-26 branch checked out in a worktree created by :
>
> cd emacs/master
> git worktree add -b emacs-26 ../emacs-26 origin/emacs-26
>
> At some point, that worktree was in a confusing state, so I deleted it,
> intending to do a fresh checkout. So I repeated the above command, but
> it complained "branch emacs-26 already exists". So I dropped the '-b
> emacs-26', and the command seemed to work.
>
> However, 'git status' in the new worktree says "not on any branch",
> 'git push' complains about fast-forward, and 'git pull' says not on a
> branch.
>
> How do I fix this?
>
> --
> -- Stephe
>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 13:51 git: how to restore a deleted worktree? Stephen Leake
  2018-01-04 14:06 ` Noam Postavsky
  2018-01-04 14:07 ` Nathan Moreau
@ 2018-01-04 14:49 ` Andreas Schwab
  2018-01-04 18:29 ` Stefan Monnier
  3 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2018-01-04 14:49 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

On Jan 04 2018, Stephen Leake <stephen_leake@stephe-leake.org> wrote:

> How do I fix this?

Just checkout the desired branch.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 13:51 git: how to restore a deleted worktree? Stephen Leake
                   ` (2 preceding siblings ...)
  2018-01-04 14:49 ` Andreas Schwab
@ 2018-01-04 18:29 ` Stefan Monnier
  3 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2018-01-04 18:29 UTC (permalink / raw)
  To: emacs-devel

> git worktree add -b emacs-26 ../emacs-26 origin/emacs-26
[...]
> So I dropped the '-b emacs-26', and the command seemed to work.
[...]
> However, 'git status' in the new worktree says "not on any branch", 

So you did:

    git worktree add ../emacs-26 origin/emacs-26

which means "give me a worktree that shows the content of the remote
branch origin/emacs-26".  So it indeed didn't use any (local) branch for
that, and instead used a "detached head" (IIRC the terminology used by
Git).

You could have used

    git worktree add ../emacs-26 emacs-26

since you apparently already had a local `emacs-26` branch (which
presumably tracks the remote origin/emacs-26).

But as Andreas explains, it's easy to fix without a new "git worktree":
just do `git checkout emacs-26`.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 14:06 ` Noam Postavsky
@ 2018-01-04 22:04   ` Stephen Leake
  2018-01-04 23:14     ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Leake @ 2018-01-04 22:04 UTC (permalink / raw)
  To: emacs-devel

Noam Postavsky <npostavs@users.sourceforge.net> writes:

> On Thu, Jan 4, 2018 at 8:51 AM, Stephen Leake
> <stephen_leake@stephe-leake.org> wrote:
>
>> At some point, that worktree was in a confusing state, so I deleted it,
>> intending to do a fresh checkout. So I repeated the above command, but
>> it complained "branch emacs-26 already exists".
>
> You need 'git worktree prune' to make git remove the bookkeeping info
> about that deleted worktree (possibly you have delete your new tree
> first, not sure how pruning works when you've recreated a new worktree
> in the same place).

I forgot to mention I did that; deleted the tree, ran 'git worktree 'prune'.

But that apparently does not remove the emacs-26 branch.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 14:07 ` Nathan Moreau
@ 2018-01-04 22:07   ` Stephen Leake
  2018-01-07 20:15     ` Nathan Moreau
  0 siblings, 1 reply; 10+ messages in thread
From: Stephen Leake @ 2018-01-04 22:07 UTC (permalink / raw)
  To: emacs-devel

Nathan Moreau <nathan.moreau@m4x.org> writes:

> It's not clear what you did when you `deleted' the worktree. The
> proper way to cleanup worktrees is
> + first to remove the associated branch (emacs-26)

What is the git command for this?

> This is probably what you need to do to get back to a clean state in
> your case, before going to `git worktree add....' again.
> If you just run the prune command, git won't prune anything as the
> branch still exists.

It did delete stuff from the .git/worktrees directory, since the
emacs-26 worktree no longer existed.


-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 22:04   ` Stephen Leake
@ 2018-01-04 23:14     ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2018-01-04 23:14 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

On Jan 04 2018, Stephen Leake <stephen_leake@stephe-leake.org> wrote:

> But that apparently does not remove the emacs-26 branch.

Of course it doesn't, branches exist independent of whether they are
checked out.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-04 22:07   ` Stephen Leake
@ 2018-01-07 20:15     ` Nathan Moreau
  2018-01-07 20:22       ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Nathan Moreau @ 2018-01-07 20:15 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

On 4 January 2018 at 23:07, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:
> Nathan Moreau <nathan.moreau@m4x.org> writes:
>
>> It's not clear what you did when you `deleted' the worktree. The
>> proper way to cleanup worktrees is
>> + first to remove the associated branch (emacs-26)
>
> What is the git command for this?
>

To remove a branch: git -d <branch>
(or if the branch is not merged and you want to discard your work: git
-D <branch>)


>> This is probably what you need to do to get back to a clean state in
>> your case, before going to `git worktree add....' again.
>> If you just run the prune command, git won't prune anything as the
>> branch still exists.
>
> It did delete stuff from the .git/worktrees directory, since the
> emacs-26 worktree no longer existed.
>

You should really not touch what is inside the .git directory directly
(because of the risk to mess things up).

To wrap things up, to discard a worktree you should:
- remove the branch associated to it (you can find it out using the
command `git worktree list --porcelain')
- then run `git worktree prune'

In particular, I recommand you **not** to remove the directory of the
worktree manually, and not to touch the content of .git manually
either.

On 4 January 2018 at 23:07, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:
> Nathan Moreau <nathan.moreau@m4x.org> writes:
>
>> It's not clear what you did when you `deleted' the worktree. The
>> proper way to cleanup worktrees is
>> + first to remove the associated branch (emacs-26)
>
> What is the git command for this?
>
>> This is probably what you need to do to get back to a clean state in
>> your case, before going to `git worktree add....' again.
>> If you just run the prune command, git won't prune anything as the
>> branch still exists.
>
> It did delete stuff from the .git/worktrees directory, since the
> emacs-26 worktree no longer existed.
>
>
> --
> -- Stephe
>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: git: how to restore a deleted worktree?
  2018-01-07 20:15     ` Nathan Moreau
@ 2018-01-07 20:22       ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2018-01-07 20:22 UTC (permalink / raw)
  To: Nathan Moreau; +Cc: Stephen Leake, emacs-devel

On Jan 07 2018, Nathan Moreau <nathan.moreau@m4x.org> wrote:

> To wrap things up, to discard a worktree you should:
> - remove the branch associated to it (you can find it out using the
> command `git worktree list --porcelain')

No, there is no need to remove the branch.  You cannot do that anyway as
long as it is checked out.

> - then run `git worktree prune'

> In particular, I recommand you **not** to remove the directory of the
> worktree manually,

No, that _is_ the right way to remove a worktree.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-01-07 20:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-04 13:51 git: how to restore a deleted worktree? Stephen Leake
2018-01-04 14:06 ` Noam Postavsky
2018-01-04 22:04   ` Stephen Leake
2018-01-04 23:14     ` Andreas Schwab
2018-01-04 14:07 ` Nathan Moreau
2018-01-04 22:07   ` Stephen Leake
2018-01-07 20:15     ` Nathan Moreau
2018-01-07 20:22       ` Andreas Schwab
2018-01-04 14:49 ` Andreas Schwab
2018-01-04 18:29 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).