Skip to content

Instantly share code, notes, and snippets.

@rocktimsaikia
Created August 15, 2020 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rocktimsaikia/6bedf5561056082c51157c2911954624 to your computer and use it in GitHub Desktop.
Save rocktimsaikia/6bedf5561056082c51157c2911954624 to your computer and use it in GitHub Desktop.
Most used git commands

Initialize Git: git init

et everything ready to commit: git add .

et custom file ready to commit: git add index.html

ommit changes: git commit -m "Message"

ommit changes with title and description: git commit -m "Title" -m "Description..."

dd and commit in one step: git commit -am "Message"

emove files from Git: git rm index.html

pdate all changes: git add -u

emove file but do not track anymore: git rm --cached index.html

ove or rename files: git mv index.html dir/index_new.html

ndo modifications (restore files from latest commited version): git checkout -- index.html

estore file from a custom commit (in current branch): git checkout 6eb715d -- index.html

ndo latest commit: git reset --soft HEAD~

pdate most recent commit (also update the commit message): git commit --amend -m "New Message"

ename branch: git branch -m branchname new_branchname

how all completely merged branches with current branch: git branch --merged

top merge (in case of conflicts): git merge --abort

top merge (in case of conflicts): git reset --merge // prior to v1.7.4

ndo local merge that hasn't been pushed yet: git reset --hard origin/master

quash multiple commits into one: git rebase -i HEAD~3 (source)

quash-merge a feature branch (as one commit): git merge --squash branchname (commit afterwards)

dd or edit gitignore: nano .gitignore

rack empty dir: touch dir/.gitkeep

Log

how commits: git log

how oneline-summary of commits: git log --oneline

how oneline-summary of commits with full SHA-1: git log --format=oneline

how oneline-summary of the last three commits: git log --oneline -3

how only custom commits: git log --author="Sven" git log --grep="Message" git log --until=2013-01-01 git log --since=2013-01-01

how only custom data of commit: git log --format=short git log --format=full git log --format=fuller git log --format=email git log --format=raw

how changes: git log -p

how every commit since special commit for custom file only: git log 6eb715d.. index.html

how changes of every commit since special commit for custom file only: git log -p 6eb715d.. index.html

how stats and summary of commits: git log --stat --summary

how history of commits as graph: git log --graph

how history of commits as graph-summary: `git log --oneline --graph --all --decorate

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