Skip to content

Instantly share code, notes, and snippets.

@JulianeAlbuquerque
Last active April 19, 2017 13:09
Show Gist options
  • Save JulianeAlbuquerque/08d8a6de523afb5bf52e71fe27aee603 to your computer and use it in GitHub Desktop.
Save JulianeAlbuquerque/08d8a6de523afb5bf52e71fe27aee603 to your computer and use it in GitHub Desktop.
Command Git

Command Git

Tags

Show Tag's

git tag -l

git show <TAG>

Create Tag

git tag -a <NOME_DA_TAG> -m 'description'

git push --tag

git tag -a v1.2 9fceb02 -m "Message here"

Delete Tag

git push origin :refs/tags/<NOME_DA_TAG>

Deleting Branches

git branch -d NOME_DA_BRANCH

git branch -dr origin/NOME_DA_BRANCH

Revert commit

Temporarily switch to a different commit

git checkout 0d1d7fc32 git checkout -b old-state 0d1d7fc32

Hard delete unpublished commits

# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.

Undo published commits with new commits

# This will create three separate revert commits:
git revert a867b4af 25eee4ca 0766c053

# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD

# Reverting a merge commit
git revert -m 1 <merge_commit_sha>

# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .

# Then commit. Be sure and write a good message describing what you just did
git commit
@JulianeAlbuquerque
Copy link
Author

JulianeAlbuquerque commented Apr 19, 2017

Interactive rebase

git rebase -i HEAD~5

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