Skip to content

Instantly share code, notes, and snippets.

@simplay
Last active August 24, 2017 08:12
Show Gist options
  • Save simplay/8b68cdccaa97c8f910e1 to your computer and use it in GitHub Desktop.
Save simplay/8b68cdccaa97c8f910e1 to your computer and use it in GitHub Desktop.

helpful sources:

Squashing last 3 commits to 1 commit: git rebase -i HEAD~3 source

Undo a rebase (commit --amend or similar thintgs):

git reflog # rebase started at HEAD@{8}
git reset --hard HEAD@{9}

Squash all commits into one: git reset $(git commit-trreset $(git commit-tree HEAD^{tree} -m "commit message")

remove an cached file git rm --cached path/file.extension

remove an cached directory plus its files git rm --cached -r somedir

Delete untracked files and directories git clean -df

Commit fraud

git rebase -i HEAD~#commits
git commit --amend --author="Author Name <email@address.com>"
git push -f

reset local master:

git fetch origin
git reset --hard origin/master

http://stackoverflow.com/questions/927358/how-to-undo-last-commits Reset to a specific commit:

git reset --hard COMMIT_HASH

show code diff of a COMMIT: git show COMMIT

delete branch globally: git push origin --delete <branchName>

delete local merged branches git branch -D «git branch --merged | grep -v * | xargs``

delete untracked files git clean -f

Revers an gitcommit --amend`

See git reflog

# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before 
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
`git reset --soft HEAD@{1}`

# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
# previous command. It's now pointing at the erroneously amended commit.)
`git commit -C HEAD@{1}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment