Skip to content

Instantly share code, notes, and snippets.

@0mppula
Last active May 4, 2022 07:32
Show Gist options
  • Select an option

  • Save 0mppula/17393b72ba54f10902a2ed325ac6d3dd to your computer and use it in GitHub Desktop.

Select an option

Save 0mppula/17393b72ba54f10902a2ed325ac6d3dd to your computer and use it in GitHub Desktop.
Git cheat cheat new code session

Pull from master and create a new branch

git checkout master
git pull
git checkout -b <branch>

When mergin you have to be in the branch you want to merge into

In this example we are merging feature/new-feature branch with the master branch.

* feature/new-feature
git merge <branch>  // master

Git log

git log --pretty=oneline

Delete merged branch (only possible if not HEAD):

git branch -d branchname 
git branch --delete branchname

Fix a type-o in a commit message

git commit --amend -m "<new commit message>"

Unstage a file

git restore --staged <filename>

Restore a file

git restore <filename>

Remove a file

git rm <filename>

Revert all the changes made to every file in the working copy

git checkout .

Revert (go back) to commit (recording the "revert" in the history)

git revert <commit hash>

Reset (go back) to commit (doesn't record the "reset" in the history)

git reset --hard <commit hash>

View contents of a file as it was at a specific commit

git show <009b7c0>:<filename>

Set the contents of a file to a specific committed version

git checkout <009b7c0> -- <filename>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment