mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-10 15:47:54 +02:00
Add "Useful Git Commands" page
@ -1,29 +1,53 @@
|
|||||||
### Branches
|
> [Wiki](Home) ▸ [Development](development) ▸ **Useful Git Commands**
|
||||||
* list all branches (incl. remotes)
|
|
||||||
|
|
||||||
> `git branch -a`
|
Useful Git Commands
|
||||||
>
|
=======
|
||||||
> * master
|
|
||||||
>
|
|
||||||
> remotes/origin/14.2
|
|
||||||
|
|
||||||
* 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 <branch> origin/<branch>`
|
```git status```
|
||||||
|
***
|
||||||
|
|
||||||
* switch to branch existing on your local repo
|
### Branch
|
||||||
|
In order to get list of branches or create one.
|
||||||
|
|
||||||
> `git checkout <branch>`
|
List of branches: ```git branch -a```
|
||||||
|
|
||||||
* merge a commit from a different branch (after pulling/fetching!)
|
Create branch: ```git branch <your branch name>```
|
||||||
|
|
||||||
> `git cherry-pick <sha1>`
|
Delete branch: ```git branch -b <branch name>```
|
||||||
|
|
||||||
* merge a not pushed commit from a different local repository
|
switch to another branch: ```git checkout <branch name>```
|
||||||
|
<br> e.g.: ```git checkout 17.1```
|
||||||
|
|
||||||
> `git --git-dir=../<some_other_repo>/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k`
|
***
|
||||||
|
### Merge
|
||||||
|
Sometimes we need to merge our branch with master.
|
||||||
|
```
|
||||||
|
git checkout <your branch>
|
||||||
|
git rebase master
|
||||||
|
```
|
||||||
|
|
||||||
* remove empty commits after import of partial repo via Github importer
|
or when we want to merge only a single commit into our branch from another branch (e.g. backporting):<br>
|
||||||
(has to be done with every branch and everyone has to clone the repo again!)
|
```
|
||||||
|
git cherry-pick <commit hash>
|
||||||
|
```
|
||||||
|
`--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
|
***
|
||||||
|
|
||||||
|
### Revert
|
||||||
|
For reverting uncommitted changes on files you may run the following:
|
||||||
|
```
|
||||||
|
git checkout <filename>
|
||||||
|
```
|
||||||
|
and for reverting commits which are not pushed you may use:
|
||||||
|
```
|
||||||
|
git reset --hard <commit hash>
|
||||||
|
```
|
||||||
|
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.*
|
||||||
|
Reference in New Issue
Block a user