Git: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Configuration ==
== Configuration ==


<pre>
<syntaxhighlight lang="bash">
git config --global core.editor "vim"
git config --global core.editor "vim"
git config --global user.name "name"
git config --global user.name "name"
Line 7: Line 7:
git config --local user.name "name"
git config --local user.name "name"
git config --local user.email "name@mydomain.com"
git config --local user.email "name@mydomain.com"
</pre>
</syntaxhighlight>


== Maintainance ==
== Maintainance ==
Line 20: Line 20:
   |  
   |  
   | <nowiki>git branch -l feature/* | xargs git branch -D</nowiki>
   | <nowiki>git branch -l feature/* | xargs git branch -D</nowiki>
|-
  |
  | <nowiki>git branch -l feature/* bugfix/* hotfix/* | xargs git branch -D</nowiki>
|-
|-
   | Check why a file was ignored
   | Check why a file was ignored
   | git check-ignore -v config.php
   | git check-ignore -v config.php
|-
  | Clone a specific branch
  | git clone -b staging project project_staging
|-
  | Clear tags not in remote repository
  | git fetch --prune --prune-tags
|}
|}


== Unknown ==
== Undo ==
 
<source lang="bash">
# Remove feature branches.
git branch -d `git branch | grep 'feature/' | xargs`


<pre>
# Unstage a file
# Unstage a file
git reset --  src/sequelize-eparking/models/Fee.js
git reset --  src/sequelize-eparking/models/Fee.js
# Remove unused branches
git branch | grep 'feature/' | cut -c3- | xargs git branch -D
# See local and remote branches
git branch -v -a
master                                c313bf9 ...
remotes/origin/static-files-2        be32085 ...
remotes/origin/static-files-3        e9021d8 ...
...
# Checkout remote branch.
git checkout -b static-files-3 remotes/origin/static-files-3


# Latest commit > stage
# Latest commit > stage
git reset HEAD^
git reset HEAD^
git reset HEAD~1  # if symbol ^ escaped
git checkout upstream/develop composer.lock
git checkout upstream/develop composer.lock
</pre>


git config --global core.editor "vim"
== Statistics ==
git config --global user.name "name"
git config --global user.email "name@mydomain.com"
git config --local user.name "name"
git config --local user.email "name@mydomain.com"


# Check why a file was ignored.
<syntaxhighlight lang="bash">
git check-ignore -v config.php
# stat for single commit
</source>
git diff 5741a4^..5741a4 --stat
git diff 5741a4^..5741a4 --shortstat


<source lang="bash">
# Get commits count of someone.
# Get commits count of someone.
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit'
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit'
Line 68: Line 59:
git diff 980b^ 980b | grep '^-[^-]' | wc -l
git diff 980b^ 980b | grep '^-[^-]' | wc -l
git diff 980b^ 980b | grep '^+++' | wc -l
git diff 980b^ 980b | grep '^+++' | wc -l
</source>
</syntaxhighlight>
 
== Unknown ==
 
<syntaxhighlight lang="bash">
# See local and remote branches
git branch -v -a
master                                c313bf9 ...
remotes/origin/static-files-2        be32085 ...
remotes/origin/static-files-3        e9021d8 ...
...
 
# Checkout remote branch.
git checkout -b static-files-3 remotes/origin/static-files-3
</syntaxhighlight>


https://docs.github.com/en/github/extending-github/git-automation-with-oauth-tokens
https://docs.github.com/en/github/extending-github/git-automation-with-oauth-tokens

Latest revision as of 14:05, 16 October 2025

Configuration

git config --global core.editor "vim"
git config --global user.name "name"
git config --global user.email "name@mydomain.com"
git config --local user.name "name"
git config --local user.email "name@mydomain.com"

Maintainance

Purpose Command
Delete unused branches git branch -l feature/* | xargs git branch -d
git branch -l feature/* | xargs git branch -D
git branch -l feature/* bugfix/* hotfix/* | xargs git branch -D
Check why a file was ignored git check-ignore -v config.php
Clone a specific branch git clone -b staging project project_staging
Clear tags not in remote repository git fetch --prune --prune-tags

Undo

# Unstage a file
git reset --  src/sequelize-eparking/models/Fee.js

# Latest commit > stage
git reset HEAD^
git reset HEAD~1   # if symbol ^ escaped
git checkout upstream/develop composer.lock

Statistics

# stat for single commit
git diff 5741a4^..5741a4 --stat
git diff 5741a4^..5741a4 --shortstat

# Get commits count of someone.
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit'
git log --author='Me' --since='2019-01-01' --before='2019-12-31' | grep '^commit' | wc -l
git diff 980b^ 980b | grep '^+[^+]' | wc -l
git diff 980b^ 980b | grep '^-[^-]' | wc -l
git diff 980b^ 980b | grep '^+++' | wc -l

Unknown

# See local and remote branches
git branch -v -a
master                                c313bf9 ...
remotes/origin/static-files-2         be32085 ...
remotes/origin/static-files-3         e9021d8 ...
...

# Checkout remote branch.
git checkout -b static-files-3 remotes/origin/static-files-3

https://docs.github.com/en/github/extending-github/git-automation-with-oauth-tokens