Skip to content

Instantly share code, notes, and snippets.

@ederrafo
Last active September 22, 2022 17:06
Show Gist options
  • Save ederrafo/ecc071859b151d1f52f9 to your computer and use it in GitHub Desktop.
Save ederrafo/ecc071859b151d1f52f9 to your computer and use it in GitHub Desktop.
git version

To revert git add, use this: $ git reset

git tag

supports two types of tags: lightweight and annotated (lijeras y anotadas) Git has the ability to tag specific points in history as being important.

$ git tag

search for tags that match a particular pattern. (Listing tag wildcards requires -l or --list option)

$ git tag -l "v1.8.5*"

A lightweight tag is very much like a branch that doesn’t change it’s just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).

Un lightweight

Know which branch standing and view files modified

    $ git status -bsuno
    ## <branch name>
    M ...
    M ....

Resolve conflicts

Requirements: - Remote repos : upstream (destination) and origin (source) - Branchs: master and any-branch Resolve:

        $ git co any-branc
            Switched to branch 'any-branch'
        $ git pull origin any-branch
            Already to update
        $ git co master
            Switched to branch 'master'
        $ git pull upstream master // download code from destination
            remote: Counting objects: 6, done.
            remote: Compressing objects: 100% (6/6), done.
            .
            .
        $ git co any-branch
            Switched to branch 'any-branch'
        $ git merge master
            Auto-merging test.txt
            CONFLICT (content): Merge conflict in test.txt
            Automatic merge failed; fix conflicts and then commit the result. 
After resolves conflicts:
        $ git add test.txt
        $ git cm -m 'resolves conflicts'
        Update pull request:
        $ git push origin any-branch  
src: https://confluence.atlassian.com/bitbucket/resolve-merge-conflicts-704414003.html

Conflicts:

    <<<<<<< HEAD
                /*This lines are your changes, is the source*/
    =======
               /* This lines come from destination repository*/
     >>>>>>> master

Corregir mensaje

  $ git commit -m "Incorrect message"
  Para corregir el mensaje de este último commit se hace lo siguiente:
  $ git commit -m "Correct menssage" --amend

List all the files in a commit

Preferred Way (because it's a plumbing command; meant to be programmatic):

  $ git diff-tree --no-commit-id --name-only -r bd61ad98
  index.html
  javascript/application.js
  javascript/ie6.js

Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)

 $ git show --pretty="" --name-only bd61ad98    
  index.html
  javascript/application.js
  javascript/ie6.js
  • The --no-commit-id suppresses the commit ID output.
  • The --pretty argument specifies an empty format string to avoid the cruft at the beginning.
  • The --name-only argument shows only the file names that were affected (Thanks Hank).
  • The -r argument is to recurse into sub-trees

I’ll use the “git grep” command to figure out where we’re using this route:

 $ git grep event_show

Comentario en una linea

 $ git log --oneline --graph --all

Crea y te traslada a la ramma recien creada

 $ git co -b nombre_rama

To determine where the key has already been used, open a terminal and type the ssh command. Use the -i flag to provide the path to the key you want to check:

 $ ssh -T -ai ~/.ssh/id_rsa [email protected]

Stages All

 $ git add -A 

Stages new and modified, without deleted

 $ git add . 

Stages modified and deleted, without new

 $ git add -u 

GIT LOG

$ git log

$ git log --pretty=oneline --graph --all
* 48361304ce42f4a936ea6e3e85fddfd91a6ed734 Initial commit

$ git log --pretty=format:"%h - %an, %ar : %s"
4836130 - eder pariona espinhal, hace 4 horas : Initial commit

Opción	 Descripción de la salida
 %H	     Hash de la confirmación
 %h	     Hash de la confirmación abreviado
 %T	     Hash del árbol
 %t	     Hash del árbol abreviado
 %P	     Hashes de las confirmaciones padre
 %p	     Hashes de las confirmaciones padre abreviados
 %an	    Nombre del autor
 %ae	    Dirección de correo del autor
 %ad	    Fecha de autoría (el formato respeta la opción -–date)
 %ar	    Fecha de autoría, relativa
 %cn	    Nombre del confirmador
 %ce	    Dirección de correo del confirmador
 %cd	    Fecha de confirmación
 %cr	    Fecha de confirmación, relativa
 %s	     Asunto

See history in file

 git log --follow -p src/main/resources/application-dev.properties 

See who have changed in file

git blame src/main/resources/application-dev.properties 

GIT BRANCH

To remove a remote branch (if you know what you are doing!)

 $ git push origin :the_remote_branch

== Add un repo externos a mi repo local ==

$ git remote add upstream https://[email protected]/zionteam/costamar.com.git

º === Envio mi rama local a mi repositorio remoto donde creo una rama llamada ‘epe’ ====

 $ git push https://[email protected]/ederafo/test_central.git HEAD:epe
 # Para no tipear toda la url lo añado a origin
 $ git remote add origin https://[email protected]/ederafo/test_central.git
 # ahora envio los cambios de mi rama :
 $ git push origin epe

=== HOW TO SEARCH A GIT REPOSITORY BY COMMIT MESSAGE ? ===

To search the commit log (across all branches) for the given text: Para buscar el registro de commit (en todas las ramas) para el texto dado:

 $ git log --all --grep='Build 0051'

To search the actual content of commits through a repo's history, use: Para buscar en el contenido actual de un commit a través de la historia de un repo, utilice:

$ git grep 'Build 0051' $(git rev-list --all)

git clone -b 03_views https://github.com/KodeBlog/Laradmin.git laradmin
git clone -b 03_views https://github.com/KodeBlog/Laradmin.git laradmin
git clone -b 04_database https://github.com/KodeBlog/Laradmin.git laradmin

http://stackoverflow.com/questions/7124914/how-to-search-a-git-repository-by-commit-message https://help.github.com/articles/setting-your-username-in-git/ http://stackoverflow.com/questions/1257592/how-do-i-remove-files-saying-old-mode-100755-new-mode-100644-from-unstaged-cha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment