Contesto: Sto lavorando su master aggiungendo una funzione semplice. Dopo pochi minuti mi rendo conto che non era così semplice e avrebbe dovuto essere meglio lavorare in una nuova filiale.Git: Crea un ramo da modifiche nonstage/uncommitted sul master
Questo succede sempre a me e non ho idea di come passare a un altro ramo e prendere tutti questi cambiamenti non modificati con me lasciando pulito il ramo principale. Supponevo git stash && git stash branch new_branch
sarebbe semplicemente realizzare questo, ma questo è ciò che ottengo:
~/test $ git status
# On branch master
nothing to commit (working directory clean)
~/test $ echo "hello!" > testing
~/test $ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
~/test $ git stash
Saved working directory and index state WIP on master: 4402b8c testing
HEAD is now at 4402b8c testing
~/test $ git status
# On branch master
nothing to commit (working directory clean)
~/test $ git stash branch new_branch
Switched to a new branch 'new_branch'
# On branch new_branch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/[email protected]{0} (db1b9a3391a82d86c9fdd26dab095ba9b820e35b)
~/test $ git s
# On branch new_branch
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
~/test $ git checkout master
M testing
Switched to branch 'master'
~/test $ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: testing
#
no changes added to commit (use "git add" and/or "git commit -a")
Sai se c'è qualche modo per realizzare questo?
Anche se c'è una soluzione più semplice al problema, potrebbe si specifica in quello che il risultato che si ottiene differisce da quello che volevi? – Gauthier
facendo quanto sopra o le risposte in basso, le modifiche non modificate sono sia sul master che sul nuovo ramo. Li voglio solo sul nuovo ramo, quindi posso eseguire il checkout di master e lavorare su un'altra cosa senza che queste modifiche fluttuano intorno a – knoopx
, vedere la mia risposta modificata. È necessario impegnare le modifiche locali sul nuovo ramo se si desidera eseguire il checkout di un master pulito. Le modifiche locali sono solo le differenze tra l'HEAD corrente e i tuoi file su disco. Queste modifiche sui file locali non sono versionate, devi dire a git di salvarle da qualche parte se vuoi recuperarle in seguito. – Gauthier