Last active
November 20, 2023 21:23
-
-
Save wildeng/9d95eb31a5db17d5f13e9339f68496fe to your computer and use it in GitHub Desktop.
GIT quick Reference - WIP
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
GIT quick reference - WIP | |
A collection of tips to effectively use GIT. | |
Logging | |
# Compact log and graph | |
git log --oneline --graph | |
# Log actual changes in a file | |
git log -p <filename> | |
# Log changes not yet merged to the parent branch | |
git log --no-merges ,parent_branch>.. | |
Rename a local branch | |
If you want to rename a branch | |
git branch -m <oldname> <newname> | |
if you want to rename the current branch | |
git branch -m <newname> | |
To push an delete the old branch | |
git push <remote> --delete <old_name> | |
or | |
git push <remote> :<oldname> | |
To push the new branch and reset the upstream branch | |
git push <remote> -u <newname> | |
Multi-Line message with commit | |
To write a multi-line commit without opening the editor, use the -m option using single quotes: | |
git commit -m 'Feature: [WO-164] Add ignore files to rubocop | |
quote> | |
quote> | |
* Added routes.rb to rubocop ignore file' | |
[refactoring/WO-164-move-to-jenkins 387aa73] Feature: [WO-164] Add ignore files to rubocop | |
1 file changed, 1 insertion(+) | |
Commit message with editor and template | |
Document Classification: Sensitive | |
Page 1If you want to use the editor for the commit and prefer to have a template to remember to be consistent across your commits you can drop a .gitmessage | |
file in your home folder with something similar in it: | |
Refactoring/Bugfix/Feature: [TICKET-123] Title | |
* Description | |
An then tell GIT that you want to use that file | |
# you have to pass the absolute path otherwise it will be | |
# interpreted as relative | |
git config commit.template /absolute/path/to/.gitmessage | |
Check available local and remote branches | |
git branch -v -r | |
Fix the last commit made | |
git commit --amend | |
Edit the previous n commits | |
git rebase -i HEAD~n | |
Undo the last n commits | |
git reset HEAD~n | |
List Files with conflicts when merging | |
git diff --name-only --diff-filter=U | |
Stop tracking files added to .gitignore | |
Sometimes happens that after adding a file or a folder to .gitignore you're still seeing it in a git status . What you have to do is removing it from the cache: | |
git rm --cached <filename> | |
# or | |
git rm --cached -r /path/to/folder/**/* | |
How to change upstream branch | |
git branch -u <remote/branch name> | |
How to check which branches are tracking which upstream branch | |
git branch -vv | |
How to revert a merge | |
git reset --merge | |
git revert HEAD | |
git revert -m 1 <sha-of-merge-commit> | |
Edit the configuration | |
git config --global --edit | |
Reset the author of a commit | |
git commit --amend --reset-author | |
Formatting a git log: | |
git log --date=short --format="%C(blue)%h %C(reset)%s %C(magenta)%aN %C(green ul) %ad%C(reset)" | |
Getting all your configs: | |
git config --list | |
Get the name of the previous branch | |
git rev-parse --symbolic-full-name --abbrev-ref=loose @{-1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment