Difference between revisions of "GIT"

From Hugo Villeneuve
Jump to: navigation, search
(Conversion SVN à GIT)
Line 32: Line 32:
   
 
= Conversion SVN à GIT =
 
= 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/gbjazz/ gbjazz
  +
  +
# 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
  +
  +
# 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:gbjazz.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/section-nouvelles
  +
  +
$> git checkout -b section-nouvelles origin/section-nouvelles
  +
Branch section-nouvelles set up to track remote branch section-nouvelles from origin.
  +
Switched to a new branch 'section-nouvelles'

Revision as of 00:23, 19 February 2013

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}

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/gbjazz/ gbjazz
  1. If you want to keep other remote branches in your repo, you want to create a
  2. local branch for each one manually. If you don't do this, the branches won't
  3. get cloned in the final step.

git checkout -b local_branch remote_branch

  1. Tags are imported as branches. You have to create a local branch, make a tag
  2. 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

  1. 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

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

git checkout -b local_branch origin/remote_branch

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

git remote rm origin

  1. Push changes to new remote repository (example Assembla)

git remote add origin git@git.assembla.com:gbjazz.git git checkout master git push --tags git push origin master git checkout branch1 git push origin branch1 ...

  1. When cloning and to track remote branch:

$> git branch -a

  • master
 remotes/origin/HEAD -> origin/master
 remotes/origin/master
 remotes/origin/section-nouvelles

$> git checkout -b section-nouvelles origin/section-nouvelles Branch section-nouvelles set up to track remote branch section-nouvelles from origin. Switched to a new branch 'section-nouvelles'