Skip to content

Latest commit

 

History

History
55 lines (52 loc) · 1.78 KB

File metadata and controls

55 lines (52 loc) · 1.78 KB
layout post
title Git
categories
Git
visible true

All about git

- Discarding all local changes in a file

$ git checkout HEAD Can't be undone

- Restoring a deleted File

$ git checkout HEAD

Discarding chunks/lines in a File

$ git checkout -p

Discarding all local changes

$ git reset --hard HEAD Can't be undone

Fixing the last commit

$ git commit --amend -m "Correct" --amend rewrites history!

Reverting a commit in the middle

$ git revert <commit_hash>

Resetting to an old revision

$ git reset --hard <commit_hash> $ git reset --mixed <commit_hash> sets your HEAD

Resetting a File to an old revision

$ git checkout <commit_hash> -- -- means we are not talking about branch

Reflog A journal that logs every movement of the HEAD pointer

$ git reflog $ git branch <branch_name> <commit_hash>

Recovering deleted branch

$ git reflog $ git branch <branch_name> <commit_hash>

Moving a commit to a new branch

$ git branch <branch_name> $ git reset HEAD~1 --hard

Moving a commit to a different branch

$ git checkout <branch_name> $ git cherry-pick <hash_commit> $ git checkout master $ git reset --hard HEAD~1

Interactive rebase

  • How far you want to go? base
  • $ git rebase -i HEAD~3

Editing old commit messages

Fixing the last commit $ git rebase -i HEAD~3 then use reword option

Deleting old commits same as above but remove lines from unwanted commits

Squashing multiple commits into one

$ git rebase -i HEAD~3 ...then use "squash" option

Adding a change to an old commit

$ git add $ git commit --fixup <commit_hash> $ git rebase -i HEAD~4 --autosquash nothing to do in the next step

Splitting and Editing an old commit