Skip to content

Instantly share code, notes, and snippets.

@rwehresmann
Last active August 7, 2017 01:58
Show Gist options
  • Select an option

  • Save rwehresmann/42c7a59f9682a7d9680e5dd18f957cd4 to your computer and use it in GitHub Desktop.

Select an option

Save rwehresmann/42c7a59f9682a7d9680e5dd18f957cd4 to your computer and use it in GitHub Desktop.
Git beyound the basics

Stash altearions

  • git stash -u: store all your current changes to check in another time. For instance, you are in branch A and need to go to branch B, but haven't finished the alterations in branch A yet. -u enforces that non tracked files are stashed too.
  • git stash drop: pull away your stashed changes.
  • git stash pop: restore your stashed changes.

Trace alterations and rewind

  • git reflog: show all explicit changes made in your repo.
  • git reflog show [BRANCH]: show all explicit changes made in your branch.
  • git reset --hard [HASH]: reflog associate to each change a hash, and specifying it in this command make you return your repo to this stage.

Log utilities

  • git log --oneline --decorate --graph --all -30:
    • --oneline: one line log version.
    • --decorate: display the local and remote branches along with the commit hash.
    • --graph: draw simple lines to represent branches.
    • --all: search in all branches (instead only the current).
    • -30: number limit of logs to show.
  • git log --pretty=format:'%C(yellow)%h%C(reset) - %an [%C(green)%ar%C(reset)] %s': prettify log in a specific format.
  • git log --grep -E -i 'cach(e|ing)': search logs by commit message
    • --grep: says that you will search by a specific string or pattern.
    • -E: you will use regular expressions.
    • -i: case insensitive.
    • git log -S [PIECE_OF_CODE]: search logs by code change (for instance, PIECE_OF_CODE = your_method_name). -S is the argument that allow this kind of search.
    • git log -- [FILE_NAME: file specific log.
    • git blame [FILE_NAME]: shows what revision and author last modified each line of the file.
    • git show [COMMIT_HASH]: shows all alterations made in a specific commit (like a diff file).

Alias

  • git config --global alias.car 'commit --amend --no-edit': example of hot to create an alias.

Undoing

  • git reset [FILENAME]: remove from staging area
  • git reset --soft HEAD^: reset the branch to the point to the point that parent commit was, but don't change the index and working directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment