Skip to content

Instantly share code, notes, and snippets.

@luc0
Last active March 26, 2020 15:24
Show Gist options
  • Save luc0/2f1173e015da9b24be320fc9bea0d2b3 to your computer and use it in GitHub Desktop.
Save luc0/2f1173e015da9b24be320fc9bea0d2b3 to your computer and use it in GitHub Desktop.

Require forked repository

only change version to my branch name, adding "dev-" to the branch. add repository url (fork)

"repositories":
[
    {
        "type": "vcs",
        "url": "http://github.com/yourname/packageName"
    }
],
"require": {
    "owner/packageName": "dev-my-bugfix"
},

View logs

(experimental command)

git log --no-merges --author="Pattern" --name-only --pretty=format:"" | sort -u

Shortcuts

git commit -am “(message)”

Agrega todos los cambios y commitea

Undoing changes

git revert <commit>

Nuevo commit que revierte cambios de [commit] y lo aplica al branch

git reset <file>

Saca el archivo del staging area. No borra los cambios.

Rewriting git history

git commit --ammend

Al ultimo commit le agrega los staged changes, como si hubieras agregado todo junto.

git reset <commit>

[ojo] Deshaces todos los commits despues de [commit]. Preserva los cambios locales.

git reset --hard <commit>

[ojo] Deshace toda la historia y cambios y vuelve al [commit] especificado.

Stash

git stash

Guarda cambios

git stash pop

Aplica cambios del ultimo stash y dropea el stash. (a diferencia de apply que no lo dropea)

git stash apply (stash id)

Aplica cambios del stash

git stash list

Lista stashes

git stash drop

Borra el ultimo stash

Config

git config --global user.name <name>
git config --global user.email <email>

Setea el autor de los commits

Pull

git pull --rebase

Se le setea que haga un rebase para integrar los branches. Por default el pull hace merge.

git fetch --all
git pull --all

Actualizamos todos los branches

Rebase

Si el default del pull es rebase, entonces solo pararse en el branch actual y hacer:

git pull origin master

Para continuar el rebase

git rebase --continue

Abortar

git rebase --abort

Push

git push <remote> --force

[ojo] Hace un push sobre-escribiendo cambios. Puede haber perdida de cambios.

Commits

git cherry-pick <commit-hash>

Toma un commit y lo aplica al branch actual (a diferencia de merge/rebase que lo hace con varios commits) Un caso de uso sería EJ: hice un fix en el branch feature-1 (en medio de otros commits), y necesito aplicarlo a master.

git cherry-pick -x <commit-hash>

Idem. Pero genera un commit message estandarizado. De esta forma es mas facil evitar conflictos.

Tags

# --all will fetch all the remotes.
# --tags will fetch all tags as well
git fetch --all --tags --prune
git checkout tags/<tag_name> -b <branch_name>

ver mas acá

Merge fast-forward

https://sandofsky.com/images/fast_forward.pdf

Tags

Hotfix

  • salir con branch del ultimo tag
  • crear release

Feature

RESET

git reset head~1 --soft

Corre el head N commits anteriores (depende el numero despues del ~), local deja los cambios y se pueden stashear. https://www.atlassian.com/git/tutorials/undoing-changes/git-reset

IMPORTANT: use git reset on local. if it's public use revert

The point is, make sure that you’re using git reset on a local experiment that went wrong—not on published changes. If you need to fix a public commit, the git revert command was designed specifically for this purpose.

FIXING: creating branch from QA instead MASTER

FIX MASTER

Si el branch se commiteo a branch, se puede volver para atras con git reset head~1 --soft (o la cantidad que fueran)

FIX BRANCH

Crear un nuevo branch desde MASTER, comparar el branch con el que esta roto (con cosas de QA) y ver que archivos salvar. (los que correspondan al branch, y omitir cosas de QA). Copiarlas a mano. Archivo x archivo

GET PARENT BRANCH

git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'

https://stackoverflow.com/questions/3161204/find-the-parent-branch-of-a-git-branch

LOGS desde consola

git log --graph --decorate

Crear repositorio desde la consola

curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment