[git] - Git Basic Formation
Why? What? How? Git is a collection of command line utilities that track and record changes in files. With it you can restore old versions of your project,...
My team follow this for day to day usage.
According to what you working on, you need to create a new branch to work on. This branch name MUST be in lower case, and start with the correct prefix according to its content.
hotfix-
feature-
fix-{issue_number}-
Every bug fix MUST have an associated issue.
When your create a branch, it always start from the last commit of the current branch.
So your branch may be created from develop
or master
on this project.
develop
can be merge in develop
only.master
can be merge in master
or develop
.So:
master
.develop
.develop
or master
, according to which
merging strategy need to be apply. # go on master or develop
git checkout master|develop
# update current branch
git pull
# create local branch
git checkout -b branch_name
# create remote branch
git push --set-upstream origin branch_name
# remove local branch
git branch -D branch_name
# remove remote branch
git push origin :branch_name
Add current index to the last commit and open commit message editor
git commit --amand
# or with gitconfig alias
git amand
Add current index to the last commit and keep old message
git commit --amand --no-edit
# or with gitconfig alias
git oops
The git stash command takes your uncommitted changes (both staged and unstaged) and saves them away for later use.
By default, running git stash will stash:
But it will not stash:
Use git add
for them.
You aren’t limited to a single stash. You can run git stash several times to create multiple stashes,
and then use git stash list
to view them.
$ git stash list
stash@{0}: On master: stash_message
stash@{1}: On develop: stash_message
git stash apply stash@{INDEX}
.git stash clear stash@{INDEX}
.Using git stash pop stash@{INDEX}
is equivalent to git stash apply stash@{INDEX} && git stash clear stash@{INDEX}
.
Given the this commit history
* caf0816 - (HEAD -> feature) last commit (John il y a 16 minutes)
* 71a28c3 - (origin/feature) commit two (John il y a 3 jours)
* 79bb856 - commit one (John il y a 3 jours)
If you want to go back to 79bb856
, keeping modification of commits 71a28c3
and caf0816
git reset 79bb856
If you want to go back to the exact state of 79bb856
git reset --hard 79bb856
Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow.
The general process can be visualized as the following:
From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you’d created your branch from a different commit.
Internally, Git accomplishes this by creating new commits and applying them to the specified base. It’s very important to understand that even though the branch looks the same, it’s composed of entirely new commits.
For better understanding please read this article.
This operation will rewrite the graph commit history, please only use it when you make a merge request which as conflict.
# my merge request from feature_1 to develop as conflict
# go on the feature branch
git checkout feature_1
# update graph history
git fetch
# start rebase
git rebase -p develop
# for each commit, fix conflict then
git rebase --continue
# push the new graph history of feature_1
git push --force
If you made a mistake during rebase, you can abort it and start for scratch
# for rebase not finish iet
git rebase --abort
# for rebase already finish
git reset --hard origin/feature_1
The git revert
command can be considered an ‘undo’ type command, however,
it is not a traditional undo operation. Instead of removing the commit from the
project history, it figures out how to invert the changes introduced by the
commit and appends a new commit with the resulting inverse content.
This prevents Git from losing history, which is important for the integrity of your revision history and for reliable collaboration.
This as some side effect, which need to be kept in mind:
git reset
or git rebase -i
The git cherry-pick
command can be considered an ‘clone’ type command,
it is not a traditional ‘copy’ operation. Instead of adding the commit same
from to the project history, it make a new commit with the same changes.
Given one or more existing commits, it apply the change each one introduces, recording a new commit for each.
This file can be found anywhere in the project. it ignore or force files to be follow by git.
```git exclude # ignore all files with path containing .phpunit .phpunit
# ignore only the .phpunit file next to .gitignore
/.phpunit
# force all files with path containing .phpunit to be follow
!.phpunit
# force only the .phpunit file next to .gitignore to be follow
!/.phpunit ```
A common tips, to ignore a folder but force git to create it
git exclude
/path/to/ignore
!/path/to/ignore/.gitkeep
You can add a .gitignore_global on the ~/.gitconfig
[core]
excludesfile = ~/.gitignore_global
By convention, all IDE related file MUST be ignore here, never withing the .gitignore for the projet
develop
develop
.And last but not least: Your commit message should describe what the commit, when applied, does to the code – not what you did to the code.
If all this powers are not enough for you, you may have a look to some git voodoo magic
Why? What? How? Git is a collection of command line utilities that track and record changes in files. With it you can restore old versions of your project,...
Be a good developer, follow the guideline.
My team follow this for day to day usage.
Keep in mind this just an overview of how each command interact with git.
Git is a collection of command line utilities that track and record changes in files.