Re: how to combine two clones in a collection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks, Johannes, for this explanation. I actually had to prod him
on IRC a bit more until I understood, but the result is now
available on my blog:

  http://blog.madduck.net/vcs/2007.07.11_creating-a-git-branch-without-ancestry

  [...]
  Update: Johannes Schindelin taught me how to do the same without
  touching files in .git/:

  $ git symbolic-ref HEAD refs/heads/newbranch
  [...]

  and also addressed the issue which would have all files already
  committed to the "master" branch now appear in the git status
  output as staged.

  This is because the index contains the full copy of a revision of
  a file, as it would be if committed at any point. git status shows
  the differences between what has been committed, what would be
  committed, and what is available in the working tree. Since we
  pointed HEAD to nowhere ("newbranch" does not yet exist), the
  index and what has been committed (nothing in this case) diverge,
  the files are still staged, and thus are scheduled to be part of
  the impending commit.

  The way to fix this is to remove the index:

    $ rm .git/index

  This may seem weird, but it works, because git recreates the index
  whenever you switch branches:

    piper:~> git init-db
    Initialized empty Git repository in .git/
    piper:~> echo 1 > a; git add a; git commit -m.
    Created initial commit e774324: .
    1 files changed, 1 insertions(+), 0 deletions(-)
    create mode 100644 a
    piper:~> git symbolic-ref HEAD refs/heads/newbranch
    piper:~> rm .git/index
    piper:~> git status
    # On branch newbranch
    #
    # Initial commit
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #       a
    nothing added to commit but untracked files present (use "git add" to track)
    piper:~> echo 2 > b; git add b; git commit -m.
    Created initial commit 54ff342: .
    1 files changed, 1 insertions(+), 0 deletions(-)
    create mode 100644 b
    piper:~> git branch
      master
    * newbranch
    piper:~> git checkout master
    fatal: Untracked working tree file 'a' would be overwritten by merge.
    piper:~> git checkout -f master

    Switched to branch "master"
    piper:~> git status
    # On branch master
    nothing to commit (working directory clean)
    piper:~> ls
    a
    piper:~> git checkout newbranch
    Switched to branch "newbranch"
    piper:~> git status
    # On branch newbranch
    nothing to commit (working directory clean)
    piper:~> ls
    b

  As you can see, the creation of the branch is a bit complex, but
  once you (forcefully) switched back to master, you can then
  freely switch between and commit to them.

-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
 
spamtraps: madduck.bogus@xxxxxxxxxxx
 
"when women love us, they forgive us everything, even our crimes;
 when they do not love us, they give us credit for nothing,
 not even our virtues."
                                                   -- honoré de balzac

Attachment: signature.asc
Description: Digital signature (GPG/PGP)


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux