notebook/IT/Git/Git.md

97 lines
2.5 KiB
Markdown
Raw Normal View History

2020-11-27 17:40:42 +00:00
# git
2021-04-20 21:13:14 +00:00
2021-02-17 19:26:59 +00:00
![git](../img/git.jpg)
2021-04-20 21:13:14 +00:00
2021-02-17 19:26:59 +00:00
## Clone with submodule recurse
2021-06-04 08:27:21 +00:00
add _--recurse-submodules_ to clone command
2020-11-27 17:40:42 +00:00
## Add in staging only a part of modification done in a file
`git add -p`
this will ask if you want to add each modification with this option:
2021-06-04 08:27:21 +00:00
- _y_ - Yes, add this hunk
- _n_ - No, dont add this hunk
- _d_ - No, dont add this hunk and all other remaining hunks. Useful if youve already added what you want to, and want to skip over the rest
- _s_ - Split the hunk into smaller hunks. This only works if theres unchanged lines between the changes in the displayed hunk, so this wouldnt have any effect in the example above
- _e_ - Manually edit the hunk. This is probably the most powerful option. As promised, it will open the hunk in a text editor and you can edit it to your hearts content
2020-11-27 17:40:42 +00:00
## delete a file only from git repository
`git rm -rf --cached`
## delete a file from complete history
be carefull can't push repo last time use
2021-04-19 11:31:57 +00:00
need to be in a repo with no modification
2020-11-27 17:40:42 +00:00
2021-04-20 21:13:14 +00:00
```bash
2021-06-04 08:27:21 +00:00
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $file" HEAD
2021-04-19 11:31:57 +00:00
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
```
## create a repo from other repo subfoler
- clone the first repo
- go in this directory
- launch
2021-04-20 21:13:14 +00:00
```bash
2021-04-19 11:31:57 +00:00
git filter-branch --prune-empty --subdirectory-filter "subdirectory/path" master
```
2021-04-20 21:13:14 +00:00
2021-04-19 11:31:57 +00:00
- push in your new git repo
2020-11-27 17:40:42 +00:00
## changing email adress
2021-04-20 21:13:14 +00:00
```bash
2020-11-27 17:40:42 +00:00
$ git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "schacon@localhost" ];
then
GIT_AUTHOR_NAME="Scott Chacon";
GIT_AUTHOR_EMAIL="schacon@example.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
```
## example de déclencheur git dans un dépot git
```bash
#!/bin/bash
GIT_REPO=`pwd`
SITE_NAME=notebook
TMP_GIT_CLONE="/tmp/$SITE_NAME"
PUBLIC_WWW="/usr/share/nginx/html/$SITE_NAME"
# get branch name
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
branch="${REF[2]}"
if [ "master" == "$branch" ]; then
mkdir -p $TMP_GIT_CLONE
echo "download repo"
git clone --recursive $GIT_REPO $TMP_GIT_CLONE
cd $TMP_GIT_CLONE
export PATH="$HOME/.local/bin:$PATH"
make install -e BUILDDIR=$PUBLIC_WWW
echo "Cleaning up"
rm -Rf $TMP_GIT_CLONE
fi
exit
```
2021-05-30 09:29:51 +00:00
### use git ssh over proxy socks
2021-06-04 08:27:21 +00:00
`export GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x 127.0.0.1:1080 %h %p"'`
2021-05-30 09:29:51 +00:00
### use git http over proxy socks
2021-06-04 08:27:21 +00:00
`git config http.proxy 'socks5://127.0.0.1:1080`