2014-12-24 11 views
19

(tutto fatto in poshgit su Windows 8):Come si crea un ramo master in un repository Git vuoto?

git init --bare test-repo.git 
cd test-repo.git 

(cartella viene creata con i file git-ish e le cartelle all'interno)

git status 

fatale: Questa operazione deve essere eseguita in un lavoro albero (Va bene, quindi non posso usare git status con un pronti contro termine nuda; ha senso immagino)

git branch 

(Nulla, sembra che il repository nudo non contenga alcun ramo. Devo aggiungere loro di un pronti contro termine clonato?)

cd .. 
mkdir test-clone 
cd test-clone 
git clone ../test-repo.git 

(Ottengo un avviso circa la clonazione di un repository vuoto)

cd test-repo 

(I prompt cambia per indicare io sono sul ramo master)

git branch 

(non mostra alcun risultato - eh?)

git branch master 

fatale: non è un nome oggetto valido: 'master'

Um. Quindi, come faccio a creare il ramo master nel mio repository nudo?

risposta

31

Un repository spoglio è praticamente qualcosa da cui si desidera solo eseguire il push e il recupero. Non si può fare molto direttamente "dentro": non è possibile controllare materiale, creare riferimenti (rami, tag), eseguire git status, ecc.

Se si desidera creare un nuovo ramo in un repository Git, è possibile un ramo da un clone al tuo repository:

# initialize your bare repo 
$ git init --bare test-repo.git 

# clone it and cd to the clone's root directory 
$ git clone test-repo.git/ test-clone 
Cloning into 'test-clone'... 
warning: You appear to have cloned an empty repository. 
done. 
$ cd test-clone 

# make an initial commit in the clone 
$ touch README.md 
$ git add . 
$ git commit -m "add README" 
[master (root-commit) 65aab0e] add README 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 README.md 

# push to origin (i.e. your bare repo) 
$ git push origin master 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 219 bytes | 0 bytes/s, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To /Users/jubobs/test-repo.git/ 
* [new branch]  master -> master 
6

Un ramo è solo un riferimento a un commit. Finché non si commette nulla nel repository, non si hanno rami. Puoi vederlo anche in un repository non nudo.

$ mkdir repo 
$ cd repo 
$ git init 
Initialized empty Git repository in /home/me/repo/.git/ 
$ git branch 
$ touch foo 
$ git add foo 
$ git commit -m "new file" 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 foo 
$ git branch 
* master 
+2

"Un ramo è solo un riferimento a un commit." Grazie, questo aiuta davvero a spiegare le cose! – David

+0

usa git add -A * per aggiungere le cose lì, se hai già file. – codeslapper

1

Non è necessario un secondo repository. Possiamo fornire una directory fittizia usando l'opzione --work-tree ei comandi come checkout e commit iniziano a funzionare anche su un repository vuoto. Preparare una directory fittizia:

$ rm -rf /tmp/empty_directory 
$ mkdir /tmp/empty_directory 

E ci si va:

$ cd test-repo.git    # your fresh bare repository 

$ git --work-tree=/tmp/empty_directory checkout --orphan master 
Switched to a new branch 'master'     <--- abort if "master" already exists 

$ git --work-tree=/tmp/empty_directory commit --allow-empty -m "empty repo" 

$ git branch 
* master 

$ rmdir /tmp/empty_directory 

provata su vaniglia git 1.9.1. Non ho verificato se posh-git supporta --allow-empty per eseguire un commit senza modifiche ai file (un commit solo messaggio).

+0

La bandiera "orfana" era ciò di cui avevo bisogno. Grazie! – SwankyLegg

Problemi correlati