MelmothX ha scritto:Facendo il commit, no?
E questo l'avevo capito, ma io il commit lo faccio di solito quando considero la release pronta (magari non al rilascio ma ad una situazione almeno funzionante) e per arrivare a tale release potrei a volte aver bisogno di vedere il contenuto di altri branch.
Alla fine l'add è una preparazione del commit.
Il problema è proprio prima dell'add. Nell'esempio l'add l'avevo messo perchè era il primo file; ma se dopo il commit modifico il file e faccio un checkout per switchare su un altro branch mi ritrovo questo file modificato e in caso di conflitti non mi fa nemmeno cambiare branch in modo temporaneo.
Inoltre mi capita di lavorare su due branch paralleli, feature A che contiene a.php e feature B che contiene b.php, io voglio che il branch A non veda b.php e viceversa non solo dopo i commit ma sempre, fino al merge dentro il master (e solo lì!!!). Esempio
Codice: Seleziona tutto
$ git init
$ touch index.php
$ git add .
$ git commit -m "Inizio progetto"
$ git branch A
$ git checkout A
Switched to branch "A"
$ touch a.php
$ ls
a.php index.php
$ git add a.php
$ git commit -m "Inizio A"
$ git checkout master
Switched to branch "master"
$ git branch B
$ git checkout B
Switched to branch "B"
$ touch b.php
$ git add b.php
$ git commit -m "Inizio B"
$ ls
b.php index.php
$ git checkout A
Switched to branch "A"
$ ls
a.php index.php
fin quì tutto bene, A vede a.php, B vede b.php
ora vado a sviluppare A.
Codice: Seleziona tutto
$ echo "testA" >a.php
$ cat a.php
testA
# On branch A
# Changed but not updated:
# modified: a.php
prima di continuare a sviluppare A ho bisogno di vedere B:
Codice: Seleziona tutto
$ git checkout B
error: You have local changes to 'a.php'; cannot switch branches.
$ ls -l
-rw-r--r-- 1 matteo users 6 2009-06-22 17:13 a.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
$ mv a.php c.php
$ ls -l
-rw-r--r-- 1 matteo users 6 2009-06-22 17:13 c.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
$ git status
# On branch A
# Changed but not updated:
# deleted: a.php
# Untracked files:
# c.php
$ git checkout B
Switched to branch "B"
$ ls -l
total 4
-rw-r--r-- 1 matteo users 0 2009-06-22 17:16 b.php
-rw-r--r-- 1 matteo users 6 2009-06-22 17:13 c.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
$ git checkout A
$ ls -l
$ ls -l
total 4
-rw-r--r-- 1 matteo users 0 2009-06-22 17:17 a.php
-rw-r--r-- 1 matteo users 6 2009-06-22 17:13 c.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
è tornato a.php (quello originale, cioè vuoto)
$ git status
# Untracked files:
# c.php
Oppure, più semplicemente,
Codice: Seleziona tutto
$ git status
# On branch A
nothing to commit (working directory clean)
$ ls -l
total 0
-rw-r--r-- 1 matteo users 0 2009-06-22 17:21 a.php
-rw-r--r-- 1 matteo users 0 2009-06-22 17:24 c.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
$ git status
# Untracked files:
# c.php
$ git checkout B
Switched to branch "B"
$ ls -l
total 0
-rw-r--r-- 1 matteo users 0 2009-06-22 17:25 b.php
-rw-r--r-- 1 matteo users 0 2009-06-22 17:24 c.php
-rw-r--r-- 1 matteo users 0 2009-06-22 16:59 index.php
quì non vorrei visibile c.php
Che fosse visibile me lo aspetto in quanto è "Untracked", per questo però avrei fatto (dal branch A) un git add, solamente per tracciarlo con git e lasciarlo invisibile a B e visibile ad A.
Possibile che si debba per forza fare un commit (di una situazione ancora non fissata) per andare a vedere i file di un altro branch?
Git è potente, ma ditemi che questa non è una limitazione ma che piuttosto sono io a non saperlo usare.
raffaele181188 ha scritto:Beh, la soluzione del commit è banale

più che banale è costrittiva; non so che usi tu, ma fai un commit ogni volta che vuoi vedere un altro branch o vuoi fare un git pool sul master?
raffaele181188 ha scritto:Matteo, stesso problema qui...
si, ma non è per quel lavoro; per quello me la cavo benissimo senza branch, mentre per un altro mi resterebbero molto utili
Ciao
01