Skip to content

Instantly share code, notes, and snippets.

@fodra
Last active March 30, 2017 03:27
Show Gist options
  • Save fodra/c4f461adcc345d44f4139178a892170f to your computer and use it in GitHub Desktop.
Save fodra/c4f461adcc345d44f4139178a892170f to your computer and use it in GitHub Desktop.
There are myriad of git cheatsheets out there. This one is different. This is my git cheatsheet.

Delete a crappy remote branch

The : (colon) makes all the difference. Quite dumb really.

$ git push origin :feature/crap_feature

Unstage a file

I accidentally staged a file for commit -- but I don't want to.

$ git status
On branch feature/branch
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   staged.py

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   unstaged_1.py
    modified:   unstaged_2.py

Unstage a file

Remove the file from the stage without losing the changes.

$ git reset -- <file>

Discard the changes from the staged file

You changed your mind and you want to discard changes.

$ git checkout -- <file>

Patch

Create a patch from a commit

$ git format-patch -1 <commit sha>

Apply the patch

$ patch -p1 < commit.patch

Branching

Go back to a commit

commit 26d131bbb08f1717913feb5c3afce7bf9abda345
Author: Andrew Artajos <[email protected]>
Date:   Thu Mar 23 15:41:37 2017 +1100

    case 155

commit 7a2cf4fd4256838cb9617b1ffa409ccf65c741a5
Author: Andrew Artajos <[email protected]>
Date:   Thu Mar 23 12:00:25 2017 +1100

    case 156

commit e2abb6b03f2fa4e660c357ce899a8ab352fd21b1
Merge: a01ae268 ab29e360
Author: Andrew Artajos <[email protected]>
Date:   Thu Mar 23 10:53:38 2017 +1100

    case 3

$ git checkout -b two-commits-down e2abb6b03f2fa4e660c357ce899a8ab352fd21b1

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