Skip to content

Instantly share code, notes, and snippets.

@dodbrian
Last active November 19, 2020 10:31
Show Gist options
  • Save dodbrian/29ad2c6ebc79227dd36622e277254363 to your computer and use it in GitHub Desktop.
Save dodbrian/29ad2c6ebc79227dd36622e277254363 to your computer and use it in GitHub Desktop.
Useful git commands

Useful Git Commands

undo last rebase

  1. Run git reflog and find first line from the top without rebase:
  2. Take that line number, for instance: HEAD@{5}
  3. Run git reset --hard HEAD@{5} to revert to the original state

undo last commit/merge

git reset --hard HEAD~1

undo the last commit and keep original files

git reset --soft HEAD~1

remove specific commit

git rebase --onto commitId^ commitId

push after rebase

git push -f

stash staged

  1. Stage all your files you need to stash
  2. Run git stash --keep-index. This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged).
  3. Run git stash save "good stash"
  4. Now your "good stash" has ONLY staged files
  5. Now if you need unstaged files before stash, simply apply first stash (the one created with --keep-index) and now you can remove files you stashed to "good stash"

stash specific file

git stash push -m Message /path/to/file.ext

set git commit char

git config --global core.commentChar ";"

Global git settings

[user]
	name = User Name
	email = user.name@domain.de
[winUpdater]
	recentlySeenVersion = 2.24.0.windows.2
[fetch]
	prune = true
[gui]
	recentrepo = C:/Users/name/source/repos/GitTest
[core]
	autocrlf = true
	commentChar = ";"
[alias]
	co = checkout
	rod = rebase origin/development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment