2012-08-13 9 views
5

Nel caso in cui un repository ha un numero di rami: come si può semplicemente aggiornare un file attraverso tutti i rami.Come aggiornare un file tra tutte le filiali in un repository Git

In questo caso è un file di tipo bashrc che specifica alcune variabili di ambiente. In passato ho aggiornato la versione del ramo principale, quindi ho ridefinito ogni ramo. Questo ha una sorta di overhead n + 1, vorrei evitare.

+2

Non è possibile. Scriptalo, visitando ciascun ramo a sua volta e cambiando (o copiando da qualche parte) il file su di essi. Puoi evitare il check-out prendendo esattamente lo stesso oggetto Git che hai commesso sul primo ramo (working? Master?), Se è ok, prendi ** precisamente ** lo stesso contenuto del file. – fork0

+0

Penso che sarebbe meglio sceneggiare il ribasso. L'overhead è lo stesso sia che si rebase o si copi il file in ogni ramo. Quindi, perché non avere una cronologia pulita senza messaggi duplicati e changeset? –

risposta

3

Per estendere fork0 s' comment, è necessario combinare:

Ie:

#!/bin/bash 
branches=() 
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)" 
for branch in "${branches[@]}"; do 
    if [[ "${branch}" != "master" ]]; then 
    git checkout ${branch} 
    git checkout master -- yourFile   
    fi 
done 

(Questo è essere adattato al vostro caso, dal momento che qui è sempre checkout il file dal ramo master.)

2

credo, è po 'tardi, ma seguente script vi aiuterà in questo.

#!/bin/bash 

if [ $# != 1 ]; then 
    echo "usage: $0 <filename>" 
    exit; 
fi 

branches=`git for-each-ref --format='%(refname:short)' refs/heads/\*` 
curr_branch=`git rev-parse --abbrev-ref HEAD` 
# echo "curr_branch:"$curr_branch 

filename=$1 
file_in_repo=`git ls-files ${filename}` 

if [ ! "$file_in_repo" ]; then 
    echo "file not added in current branch" 
    exit 
fi 

for branch in ${branches[@]}; do 
    if [[ ${branch} != ${curr_branch} ]]; then 
     git checkout "${branch}" 
     git checkout "${curr_branch}" -- "$filename" 
     git commit -am "Added $filename in $branch from $curr_branch" 
     echo "" 
    fi 
done 
git checkout "${curr_branch}" 
+0

Approccio interessante pure. +1 – VonC

+0

Ricordarsi di controllare le modifiche non modificate nel repository corrente. Successivamente ho aggiunto per verificare eventuali modifiche locali nel ramo corrente. ** git status --untracked-files = no --porcelain ** –

Problemi correlati