Coder Social home page Coder Social logo

git-cheatsheet's Introduction

My very own git cheatsheet and aliases

Working tree

  • git status --short --branch : short version of 'git status'
  • git checkout -- <file> : discard changes on file
  • git reset <commit> : move your HEAD pointer to another commit
  • git reset --hard : discard all changes against the HEAD pointer
  • git reset --hard <commit> : move your HEAD pointer to another commit and discard all changes
  • git reset --keep <commit> : move your HEAD pointer to another commit and preserve changes
  • git clean -f : remove all untracked files from the working tree

Comparing

  • git diff HEAD [file] : compare the working directory with HEAD
  • git diff [file] : compare the working directory with the index
  • git diff --cached [file] : compare the index with HEAD
  • git diff <commit> <commit> [files] : compare files from two commits

Committing

  • git add --patch : review each file before adding it to the index
  • git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "WIP" : commit all current changes into a WIP commit
  • git log -n 1 | grep -q -c 'WIP' && git reset HEAD~1 : undo a previous WIP commit

Fixing

  • git reset HEAD^ <file> : remove file for the previous commit
  • git commit --amend : re-apply the last commit
  • git add -A && git commit --amend --no-edit : add files to the last commit

Branching

  • git branch -a : list local and remote branches
  • git checkout --track origin/<branch> : track a remote branch in local
  • git branch -m <newname> : rename the current branch
  • git branch -m <oldname> ≤newname> : rename a branch from any other branch
  • git push --force-with-lease : push force but before it checks that your local copy is up-to-date
  • git push --set-upstream origin $(git branch | grep \* | cut -d " " -f2) : avoid specifying origin on the first push
  • git push origin --delete : remove a remote branch
  • git merge --no-edit <branch> : merge a branch into the current one without popping the editor

Browsing

  • git show <commit> : show what changes a commit has made
  • git log -p <file> : commit log with diff for a file
  • git log -S<word> : search for a word into the commit tree
  • git log --pretty=format:'%C(blue)[%cn] %ai%n %C(yellow)%h %C(reset)%s %C(cyan)%d' : beautiful and easy-to-read commit log
  • git show --pretty="" --name-only <commit> : list modified files in that commit
  • git log --follow <path> : list all commits that have modified that file

git-cheatsheet's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.