From a77a34873bd67e826a34b72f0fb3a72d162060d0 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 15 Feb 2018 16:08:57 +0100 Subject: [PATCH] Add "Useful Git Commands" page --- Useful-Git-commands.md | 60 +++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/Useful-Git-commands.md b/Useful-Git-commands.md index 2e3496d..7d8c97b 100644 --- a/Useful-Git-commands.md +++ b/Useful-Git-commands.md @@ -1,29 +1,53 @@ -### Branches -* list all branches (incl. remotes) +> [Wiki](Home) ▸ [Development](development) ▸ **Useful Git Commands** -> `git branch -a` -> -> * master -> -> remotes/origin/14.2 +Useful Git Commands +======= -* switch to a branch you never checked out before, eg. above 14.2, and set up tracking +### Status +Getting current status of repository which would show modified/merged/stashed files or commits that need to be pushed. -> `git branch --track origin/` +```git status``` +*** -* switch to branch existing on your local repo +### Branch +In order to get list of branches or create one. -> `git checkout ` +List of branches: ```git branch -a``` -* merge a commit from a different branch (after pulling/fetching!) +Create branch: ```git branch ``` -> `git cherry-pick ` +Delete branch: ```git branch -b ``` -* merge a not pushed commit from a different local repository +switch to another branch: ```git checkout ``` +
e.g.: ```git checkout 17.1``` -> `git --git-dir=..//.git format-patch -k -1 --stdout | git am -3 -k` +*** +### Merge +Sometimes we need to merge our branch with master. +``` +git checkout +git rebase master +``` -* remove empty commits after import of partial repo via Github importer -(has to be done with every branch and everyone has to clone the repo again!) +or when we want to merge only a single commit into our branch from another branch (e.g. backporting):
+``` +git cherry-pick +``` +`--no-commit`: this will help if you don't want your cherry-pick be committed right after. -> git filter-branch -f --commit-filter 'git_commit_non_empty_tree "$@"' HEAD; git push -f \ No newline at end of file +*** + +### Revert +For reverting uncommitted changes on files you may run the following: +``` +git checkout +``` +and for reverting commits which are not pushed you may use: +``` +git reset --hard +``` +or if you want to go back to latest previous commit: +``` +git reset --hard HEAD^ +``` +> **IMPORTANT:** *reset with `--hard` parameter reset your commits and you may no longer have access to your changes.*