← Main page

Git

Git log

  • git log --stat (shows log with statistics of files change)
  • git log -p (shows log and patches - changes in each commit)
  • git log --author="Dan" (shows log with a particular author of commit)
  • git log file_name (shows file changes log)
  • git log --author="Dan" file_name
  • git log --oneline (shows log with each commit as a single line)

Git diff

  • git diff commit1 commit2 (generates a patch between these two commits)

Work with branches and commits

  • git checkout commit_name
  • git checkout branch_name
  • git checkout -b branch_name (creates a new branch and switches to it)
  • git checkout commit_name file_name (extracts the file from this commit)
  • git checkout HEAD file_name (reverts previous command)
  • git branch --all

Work with remote

  • git push origin hotfix (sends to a remote repository origin branch hotfix)
  • git push origin :hotfix (removes hotfix branch in origin repository)
  • git branch -d local_branch_name (removes local branch)
  • git merge --abort (cancels merge)
  • git rebase --abort (cancels rebase)
  • git pull is git fetch, followed by git merge
  • git pull --rebase origin master
  • git reflog, then git reset --hard HEAD@{3} (cancels local rebase)