Report inadequate content

Git in Harecoded

Git log mejorado. Color y ramas dibujadas

 -

Hace unos días me llegó un tweet de Dani con uno de esos regalos que hace de tanto en cuanto, que se acuerda de los amigos y te manda algo interesante. En este caso era un artículo en inglés de Filipe Kiss donde nos enseñaba como convertir el git log de terminal en algo con cara y ojos (hacer clic en imágen).

He modificado  el comando original para que muestre el email en vez de los nombres, que tiene problemas en algunas terminales con los acentos.

Podéis probarlo tal que así:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit

Y para crear un alias permanente y llamarlo siempre con git lg las siguientes veces hay que crear el alias:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit"

Aún usando clientes gráficos como SourceTree (muy recomendable) el log en terminal sigue siendo lo más práctico para copiar y pegar en ficheros de texto para el control de cambios.

Inventazo!

Cómo borrar un tag de GitHub u otro remoto

No resulta muy obvio cómo se pueden eliminar los tags de Github. Incluso hay algunos tutoriales por ahí que no funcionan. Estos son los dos comandos que utilizo yo únicamente para borrar los tags que pongo y quito en el proyecto de SIFO en Github.

El listado de tags del repositorio local se puede sacar fácilmente usando el comando git tag, por ejemplo:

artomb@petekaner:~/htdocs/sifo$ git tag
sifo-1.9
sifo-2.1
sifo-2.2
stable-php-5.2
stable-php-5.2-last-commit

Esto es una lista de todos los tags disponibles en mi repositorio local. Si ahora decidimos que queremos borrar el tag"stable-php-5.2" de local y de remoto entonces haremos:

git tag -d stable-php-5.2
git push origin :stable-php-5.2

Atentos a los dos puntos delante del tag! El primer comando lo borra del repositorio local, y el segundo del remoto. Y listos!

Cómo hacer un sparse checkout en Git

Si quieres hacer clone de un proyecto parcialmente y no llevarte todo el árbol es muy sencillo. Si todavía no tienes los ficheros es tan sencillo como:

  • Crear una carpeta e inicializar Git
  • Activar sparse checkout
  • Decirle qué carpetas queremos
  • Añadir el repo remoto
  • Traer los ficheros con pull
Traducido en un ejemplo y sus comandos, pongamos que queremos descargar el fantástico PHP framework SIFO. Pero tan sólo queremos descargar la carpeta scripts de todo el proyecto. Entonces, sería algo tal que (puedes copiar y pegar para probarlo, luego borras la carpeta) :
mkdir mi_sparse && cd mi_sparse
git init
git remote add origin git://github.com/alombarte/SIFO.git
git config core.sparsecheckout true
echo scripts/ >> .git/info/sparse-checkout
git pull origin master
ls

Al hacer el ls verás que tan solo hay dentro la carpeta scripts. Si quieres añadir más carpetas o subcarpetas basta con que añadas más rutas al fichero sparse-checkout (la linea del ejemplo con el echo)

Fácil eh?

Move a SVN repository to Git with the whole commit history

It is in your mind, like a worm that eats away the apple, "I have to switch to Git". And one day it happens and you realize that it was not that diffcult.

I started using Git as my local repository, but still using SVN as the central repository with git itself thanks to the git svn set of commands. After some time I decided to entirely move the vast majority of projects from SVN to Git but of course not by creating a new fresh and empty repository but importing the whole svn commit history, as if the commits were made using Git itself ten years ago.

This is how you can do it:

Read more

Upload an existing Git repository to a remote GitHub, Bitbucket, Beanstalk...

These are the steps I followed to upload my existing local git repository to a new Bitbucket repository while keeping the whole commit history. You can use this simple steps to move your source code to GitHub, Beanstalk or any other repository you like, commands are just the same. I put as example Bitbucket because you can have unlimited private repositories for free.

How to do it...

  • Register to bitbucket for free, add your SSH key, and create an empty repo.
  • Add your public key to your account under Account > SSH keys (this is just pasting the content after a cat ~/.ssh/id_rsa.pub, write ssh-keygen if you don't have one)
  • Then you have an URL for cloning like this: git@bitbucket.org:your_user/your_repo.git
  • Then go to the folder where your repo is:
    cd /path/to/my/repo
  • Then upload it to Bitbucket:
    git push --mirror git@bitbucket.org:youruser/your_repo.git

That's it, with this you will be able to keep the whole log history, as shown in the sample picture

 TAGS: