Last active
July 13, 2022 20:49
-
-
Save altherlex/2d60c529010040798a3d to your computer and use it in GitHub Desktop.
git commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stty sane | |
# Discard unstaged changes | |
git checkout file | |
# For all unstaged files use: | |
git checkout -- . | |
#http://rogerdudler.github.io/git-guide/index.pt_BR.html | |
# remove from stage | |
git reset file | |
# ------- Alter Commit local | |
git reset --soft HEAD~1 | |
#http://stackoverflow.com/questions/4965639/rollback-to-last-git-commit | |
#1) To UNDO local file changes but NOT REMOVE your last commit, then use | |
git reset --hard | |
#2) To UNDO local file changes AND REMOVE your last commit, then use | |
git reset --hard HEAD^ | |
#or | |
git reset --hard HEAD~ | |
#3) To KEEP local file changes and REMOVE ONLY your last commit, then use | |
git reset --soft HEAD^ | |
#or | |
git reset --soft HEAD~ | |
#Use git status and git log frequently to observe your current state. | |
------- | |
# http://stackoverflow.com/questions/3639115/reverting-to-a-specific-commit-based-on-commit-id-with-git | |
#Do you want to roll back your repo to that state? Or you just want your local repo to look like that? | |
#if you do | |
git reset --hard c14809fa | |
#It will make your local code and local history be just like it was at that commit. But then if you wanted to push this to someone else who has the new history, it would fail. | |
#if you do | |
git reset --soft c14809fa | |
#It will make your local files changed to be like they were then, but leave your history etc. the same. | |
#-------------------- | |
# revert | |
git reset HEAD@{1} | |
# Undo modifications file in Unstaged | |
git clean -f | |
#more info http://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes | |
# delete all alteration of commit local | |
git reset --soft HEAD~1 | |
# see 3 steps logs | |
git log -n 3 | |
# review | |
git diff file | |
# commit for new branch mail | |
# git branch mail && git checkout mail | |
git co -b mail | |
# stand by on changes | |
git stash | |
git stash apply # to return | |
# seting in a branch one specific commit in another branch | |
git cherry-pick 461a34d | |
# Delete branch | |
# local | |
git branch --delete bug-subsite | |
# error: The branch 'bug-subsite' is not fully merged. | |
# If you are sure you want to delete it, run 'git branch -D bug-subsite'. | |
# remote (Git v1.7 or newer) | |
git push upstream --delete bug-subsite | |
# Set a new remote | |
git remote add origin https://github.com/user/repo.git | |
git remote -v | |
# ------------- RPM Package ------------- | |
# Opening the box | |
rpm -qlp my_package.src.rpm | |
# Get the latest tag name | |
# http://julienrenaux.fr/2013/10/04/how-to-automatically-checkout-the-latest-tag-of-a-git-repository/ | |
git describe --tags `git rev-list --tags --max-count=1` | |
# Get new tags from the remote | |
$ git fetch --tags | |
# Merge w prerence to revolse conflicts | |
git merge -Xtheirs feature/addresses | |
# Resolve conflicts in local | |
git checkout --ours myscript.py | |
git checkout --theirs myscript.py | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment