开发者

Is there a git uncheckout?

With git clone there is the option -n wich prevents a checkout of HEAD after the repository is cloned. Is there a possibility to do this manually?

Edit I think the option -n reads better in the manual than it actually is: After cloning with -n all my tools show that I still reside on the master 开发者_如何学Cbranch; the only difference being that all files are shown as deleted. It’s not really the same situation that I would call ‘not checked out’.

So maybe I should just delete HEAD?


The simplest solution would be to clone it bare:

git clone --bare your_repo bare_repo

(and delete your checked out repo)

Basically, you need to transform your repo into a bare one, which, according to this question, could be done manually with:

  • changing the .git/config file to have bare = true instead of bare = false
  • removing the contents of your_repo/* other than the .git file
  • moving the .git dir contents into your_repo/ and removing the .git dir

See also Git: Convert normal to bare repository, as mentioned by MikeSep in the comments.

If you need to uncheckout, keep bare to false, and simply remove everything but the .git. That should be like a git clone -n.


I read the original question as wanting to preserve the repo, but delete the working tree. This is useful when you want to put a project on the backburner, after some work has been done with it.

One solution is to create a branch with an empty working tree, and check out the empty branch:

git checkout --orphan archived
git reset --hard
git commit -m "Project is archived" --allow-empty

Explanation:

  1. git checkout --orphan archived creates the branch archived, with unrelated history to the project.
  2. git reset --hard removes versioned files that exist in the working tree. It preserves unversioned files, which can be cleaned out with git clean -fd if necessary.
  3. git commit -m "Project is archived" --allow-empty creates a commit with no files on the archived branch.

Unlike the git clone -n option, this method:

  • does not leave the index showing all files as "deleted"
  • unambiguously documents what happened to the work tree. The current branch name will be "archived"

A repo thusly 'archived' is ready to be re-activated by git checkout master, and can subsequently be re-archived with git checkout archived

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜