Navegación

git - 20 comandos y más

Publicado por Gastón el 06/03/2011 en GNU/Linux - Nivel Básico

Resúmen

Sistema distribuido de control de versiones

Sobre el autor

Avatar de Gastón

Gastón tiene 32 años, vive en Argentina / Santa Fe / Santa Fe y su ocupación es Desarrollador de aplicaciones web.

Forma parte del club desde 19/10/2009 a las 20:52 habiendo estado en linea 25/03/2013 a las 18:54 por última vez.

Ha publicado 54 artículos en clubdesarrolladores con un promedio de valoración de 7.97 puntos. Puedes visitar su sitio web en http://devstudios.clubdesarrolladores.com

Estadísticas

  • Leido 2294 veces
  • Valorado 10.00 puntos

1 - Instalación

$ sudo yum install git



o

$ sudo apt-get install git-core



o lo descargamos desde:

http://git-scm.com/download

Probamos

$ git --version 



git version 1.7.1


2 - Inicializar un repositorio vacío

$ cd ~/project
$ git init



3 - Agregar archivos al repositorio

$ git add .



4 - El comando commit

$ git commit -a - m "Importación inicial"



5 - Ver el log de commits

$ git log



6 - Verificar el estado actual

$ git status



7 - Encontrar diferencias entre commits

$ git diff

$ git diff commit_hash

$ git diff commit_hash_1 commit_hash_2

$ git diff --name-status

$ git diff --name-status commit_hash

$ git diff --name-status commit_hash_1 commit_hash_2

$ git diff HEAD~1



8 - Creando branches

$ git branch branch_name



9 - Listar todos los branchs

$ git branch



10 - Cambiando de branch

$ git checkout branch_name



11 - Mezclar branches (el especificado con el actual)

$ git merge branch_name



Ejemplo:
$ git checkout master
$ git merge experimental



12 - Borrando un branch

$ git branch -d branch_name



13 - Eliminando cosas del repositorio

$ git rm path

$ git rm --cached path
Quita solo del repositorio, pero no del disco



14 - Moviendose entre revisiones

$ git checkout commit_hash

$ git checkout master



15 - Moviendose sin hacer commit

$ git stash

$ git stash pop



16 - Ver stashes almacenados

$ git stash list



17 - Crear un branch de un commit anterior

$ git checkout commit_hash
$ git branch branch_name
$ git checkout branch_name


o

$ git checkout -b branch_name commit_hash



Ejemplo:

$ git checkout -b bugfix_branch HEAD~2[c/ode]

18 - Reseteando cambios

[code=bash]$ git reset
Cancela git add

$ git reset --hard
Cancela cambios y vuelve al último commit

$ git reset --hard HEAD~2
Elimina el commit



19 - Recolector de basura

$ git gc



20 - Ignorar archivos

Crear un archivo llamado .gitignore en la raiz del repositorio
Ejemplo de contenido:

*.bak
*.[ao]
tmp/
/directory1/directory2/
/directory1/file1



Apendice


A - Interfaces gráficas

		gitk
git-gui
rabbitvsc - git



B - Configuración

$ git config --global user.name "your name"
$ git config --global user.email "you@something.fun"
$ git config --global color.ui "auto"
$ git config --list



C - Trabajando con un servidor remoto

$ ssh your-user@www.your-server.com
$ mkdir -p ~/some-path/.../.../your-repo.git
$ cd ~/some-path/.../.../your-repo.git
$ git --are init
$ exit[code/]

[code=bash]$ cd your-local-git-repository
$ git remote add origin your-user@www.your-server.com:some-path/.../.../your-repo.git
$ git push origin master



a: Automatizar autenticación ssh

$ cd ~/.ssh
$ ls
$ ssh-keygen -t dsa
$ scp id_dsa.pub user@yoursever.com:.ssh/
$ ssh user@yourserver.com
$ cd ~/.ssh
$ cat id_dsa.pub >> authorized_keys
$ rm id_dsa.pub
$ exit



Referencias:

http://blog.xkoder.com/2008/08/13/git-tutorial-starting-with-git-using-just-10-commands/
http://ioconnor.wordpress.com/2009/05/15/my-git-tutorial-for-ubuntu/

Si tiene alguna pregunta sobre éste artículo por favor deje un comentario y será respondido.

Descargas

El artículo no tiene descargas asociadas

Listado de comentarios

Sus comentarios son importantes.

No hay comentarios para listar, si desea puede crear el primer comentario para este artículo.

Agregar un comentario

Debe estar identificado para agregar un comentario