How To Revert a Merge in GIT

1 |
$ git reset --hard HEAD~1 |
![]() |
Show All Branches, Local and Remote
1 |
git branch -a |
Show Local Branches
1 |
git branch |
Show Remote Branches
1 |
git branch -r |
For more information about Tagging in GIT, please visit: https://git-scm.com/book/en/v2/Git-Basics-Tagging Add an Annotated Tag:
1 2 |
git tag -a v1.0.0 -m "Software version 1.0.0" git show v1.0.0 |
Add a Lightweight Tag:
1 2 |
git tag v1.0.1 git show v1.0.1 |
Show all tags:
1 |
git tag |
Push all tags:
1 |
git push origin --tags |
Add a Tag Later:
1 2 3 4 5 6 7 8 9 10 11 12 |
git log --pretty=oneline git tag v1.0.2 5370c8da4095fefad7476fa1c226a309dd00a9f7 git tag -a v1.0.2 5370c8da4095fefad7476fa1c226a309dd00a9f7 fatal: tag 'v1.0.2' already exists git tag -d v1.0.2 Deleted tag 'v1.0.2' (was 5370c8d) git tag -a v1.0.2 5370c8da4095fefad7476fa1c226a309dd00a9f7 git push origin --tags |
Use a Tag:
1 2 |
git checkout -b {new branch name} {tag name} git checkout -b v1.0.2-from-tag v1.0.2 |
shell$ git log | head -1 commit a203e1bd04718bff10a3df4a3389c493c97c0432 Use the commit string as the last argument to the git revert command: shell$ git revert -m 1 a203e1bd04718bff10a3df4a3389c493c97c0432
Show commits and messages that match
1 |
git log --all --grep='SEARCH_STRING_HERE' |
Include code diffs
1 |
git log --all --grep='SEARCH_STRING_HERE' -p |
Include file names
1 |
git log --all --grep='SEARCH_STRING_HERE' --name-only |
1 |
git log --pickaxe-regex -p --color-words -S "theSearchString" |
First, get on the branch that you know already has the commits you are looking for:
1 |
git checkout theBranch-1234 |
Copy-and-paste the commit(s) you want:
1 |
git log |
~or~
1 |
git log -p |
Optionally, display the code changes for a visual confirmation:
1 |
git show {one or more commit ID's} |
Finally, extract the list of branches that contain the desired commits:
1 2 |
git branch --contains CommitID-A git branch --contains CommitID-B |
Example:
1 2 3 |
git log git branch --contains 097e1859f248a7aa5e148a2a946be3e360030095 git branch --contains 24339549f9f1920a33f721d3faa2538c8ba5d249 |
Recently, I wanted to see the “origin” of the git repository I was working in. The command is: git remote -v For example:
1 2 3 |
theUser@theHost$ git remote -v origin git@localhost:/volumes/data/git/thePlugin.git (fetch) origin git@localhost:/volumes/data/git/thePlugin.git (push) |
Not pushed + most recent commit:
1 |
git commit --amend |
To display the filenames included in each commit, just add the –name-only argument to git log:
1 |
git log --name-only |