Skip to content

Instantly share code, notes, and snippets.

@0guzhan
Last active July 3, 2020 11:34
Show Gist options
  • Save 0guzhan/f811c43619d225dbead9 to your computer and use it in GitHub Desktop.
Save 0guzhan/f811c43619d225dbead9 to your computer and use it in GitHub Desktop.
Undo git push and git commit
# undo last push
git push -f origin ab123c4:master
# undo last commit
git reset --hard HEAD~2
# undo last push (7cdab32)
git push origin +7cdab32^:master
# show last commit changed files
git show --pretty="format:" --name-only bd61ad98
# print diff of certain file with HEAD
git diff HEAD^^ src/main/java/com/example/service/AccountService.java
# create a branch
git branch new_branch
# create a branch from a previous commit
git branch new_branch bd61ad98
# list all branches
git branch
# create remote branch
git push origin new_branch
# delete local branch
git branch -D design-v2
# delete remote branch
git push origin --delete design-v2
# commit details for specific artifact
git log -p /app/src/main/java/net/acargil/Demo.java
# show each commit which changed this file
git log --oneline /app/src/main/java/net/acargil/Demo.java
# show last 3 git commits with these informations:
# "which files were touched?" "who changed?" "when changed?"
git log --pretty=format:"%H%n%ai%n%an (%ae)%n%B" --no-merges --name-status -n 3
# list changed files names since that commit
git diff 3eb9d24 --name-status
# remove unstaged files
git clean -fd
# revert all changes
git checkout -- .
# clean workspace
git reset --hard origin/trunk
# git add tag / remove tag
git tag mytag
git push origin --tags
git tag -d mytag
git push origin :refs/tags/mytag
# return to any commit
git checkout a6s626y
git checkout -b temp
git push -f origin HEAD:master
# reflog is for reference logs and holds current activities
git reflog
# unde git reset head
git reset 'HEAD@{1}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment