GIT

From Hugo Villeneuve
Revision as of 00:48, 19 February 2013 by Hugo (talk | contribs) (Branches)
Jump to: navigation, search

Branches

Ce script peut-être utile pour créér une branche locale, l'enregistrer sur le serveur remote et ensuite la faire suivre (track):

#!/bin/bash
# git-create-branch <branch_name>

if [ $# -ne 1 ]; then
    echo 1>&2 Usage: $0 branch_name
    exit 1
fi

branch_name=$1

git checkout -b ${branch_name}
git push origin ${branch_name}
git branch --set-upstream ${branch_name} origin/${branch_name}

Pour effacer la branche distance (remote):

 $> git push origin :${branch_name}

$> git push origin :${branch_name}

Appliquer des patches récalcitrantes

 $> git am -3 --ignore-whitespace <name.patch>

Changer le nom de l'auteur dans un commit

 $> exec git commit --amend --author="Prénom Nom <prenom.nom@hugovil.com>" -C HEAD

Conversion SVN à GIT

Cloner le répertoire SVN:

 $> git svn clone --stdlayout --no-metadata -A ~/projets/vcs/svn-to-git-migration/users.txt https://subversion.assembla.com/svn/hugovil/ hugovil

If you want to keep other remote branches in your repo, you want to create a local branch for each one manually. If you don't do this, the branches won't get cloned in the final step

 $> git checkout -b local_branch remote_branch

Tags are imported as branches. You have to create a local branch, make a tag and delete the branch to have them as tags in git. To do it with tag "v1":

 $> git checkout -b tag_v1 remotes/tags/v1
 $> git checkout master
 $> git tag v1 tag_v1
 $> git branch -D tag_v1

Ce script permet d'automatiser l'importation des tags:

#!/bin/bash

if [ ${#} -ne 1 ]; then
    echo "Missing tag name"
    exit 1
fi

TAG=${1}

# Tags are imported as branches. You have to create a local branch, make a tag
# and delete the branch to have them as tags in git. To do it with tag "v1":
git checkout -b tag_${TAG} remotes/tags/${TAG}
git checkout master
git tag ${TAG} tag_${TAG}
git branch -D tag_${TAG}

Clone your GIT-SVN repo into a clean git repo:

 $> git clone dest_dir-tmp dest_dir
 $> rm -rf dest_dir-tmp
 $> cd dest_dir

The local branches that you created earlier from remote branches will only have been copied as remote branches into the new cloned repository. For each branch you want to keep:

 $> git checkout -b local_branch origin/remote_branch

Finally, remove the remote from your clean git repo that points to the now deleted temp repo:

 $> git remote rm origin

Push changes to new remote repository (example Assembla)

 $> git remote add origin git@git.assembla.com:hugovil.git
 $> git checkout master
 $> git push --tags
 $> git push origin master
 $> git checkout branch1
 $> git push origin branch1
 $> ...

When cloning and to track remote branch:

 $> git branch -a
 * master
 remotes/origin/HEAD -> origin/master
 remotes/origin/master
 remotes/origin/bozo
 $> git checkout -b bozo origin/bozo
 Branch bozo set up to track remote branch bozo from origin.
 Switched to a new branch 'bozo'