* "bastardo" Ă© uma tradução livre da palavra "git" - "uma pessoa desagradável ou desprezĂvel", "uma pessoa desagradável ou desprezĂvel".
15 Git . , git
, -, , -, - .
, , . , git
, , , git rebase --merge --autostash
.
1. git
, git? SourceTree, , .
, , VS Code, , , .vim
:
- .
- ( ) ,
git status
. - .
- … , / .
git
, .
- , ,
git
, GUI — . - " ".
- . " " , — - .
. - , .
git pull --ff-only
— :
> git pull origin master --ff-only From ../habr2 * branch master -> FETCH_HEAD error: Your local changes to the following files would be overwritten by merge: .gitignore Please commit your changes or stash them before you merge. Aborting Updating 6d1c088..a113bf7
, , , , .
VS Code GitLens .
-
gitlens.diffWithBranch
— . - - , — . . , , , .
2. , , .
, : (--system
), (--global
) (--local
). , , — , — , — . , .
(Upd. , , worktree. worktree . .)
? , core.eol
, , user.name
user.email
, . , , , (== ) user.name
/email
.
, , . , user.name
/email
, , .
3. stash
, , , . , git stash
( . ""), "" . :
-
--amend
,stash
.git stash save
(save
). —git stash apply
( )git stash pop
( ). , , , . -
stash
- , ,stash
, , . stash
(modified) (untracked). , , , , , -.
, stash
? — WIP
( "Work In Progress"). , , .
stash
? , . , , . , "" , . - - :
git config --global alias.sshow "!f() { git stash show stash^{/$*} -p; }; f"
git config --global alias.sapply "!f() { git stash apply stash^{/$*}; }; f"
#
git stash save "hack"
#
git sshow "hack"
#
git sapply "hack"
4. "-
"
, , , "-
":
git checkout -
Windows , Linux bash
:
cd /some/long/path
...
cd -
5. ,
, — , , ( Unity).
$ git worktree add -b emergency-fix ../temp master
$ pushd ../temp
# ... hack hack hack ...
$ git commit -a -m 'emergency fix for boss'
$ popd
$ git worktree remove ../temp
, , .
6. pull
fast-forward
, , pull
fetch
( ) merge
( ), fast-forward
— , "" . , -.
git pull --rebase
, , , origin
master
pull
(, , rebase
).
, , pull
- , --ff-only
:
git config --global pull.ff only
?
- , .
- , , ( ).
- ,
pull
— ,git pull origin
master
upstream
my_feature
. - , .
7. git exclude
.gitignore
, , .
.git/info/exclude
. :
git config --global alias.exclude '!f() { vim .git/info/exclude; }; f'
( .)
.git/info/exclude
,.gitignore
.- .
- , ,
.gitignore
(untracked) . "" . ( IDE, ,.vscode/settings.json
),git rm <path> --cached
— , , exclude. - - , :
git config --global core.excludesfile <path to global .gitignore>
8. , ""
, . : , , . ( , .editorconfig
) / (.vscode/tasks.json
). , - , "" "" .
: , . :
git update-index --assume-unchanged <path to file>
" " . pull
- — , . , , no
:
git update-index --no-assume-unchanged <path to file>
9.
. , , , , , . , . , . stash
, , .
, . , , — . . ./out
— , .
, , , , .git
. , gitdir
. … git init --separate-git-dir=.git_dev
, . : , .
? , ! .git_dev
? . , :
git config --global alias.dev '!git --git-dir=\"./.git_dev\"'
:
> git status -s
?? .git_dev/
> git dev status -s
?? .git_dev/
?? .gitignore
?? Program.cs
?? habr.csproj
. , , - checkout
, (, , ).
.git/
, , , . — .gitignore
, , , -f
, — .git_dev/info/exclude
. :
# ignore all files
/*
# ignore all folders
*/
, git
, .vimrc
, .bashrc
, ~
( Windows C:\Users\%USERNAME%\
).
10.
, , . git bash
Unix-like Windows, , - , . , , :
- / ;
- ;
- .
, - , Hamster, . .git_dev
, "" .
11.
Por fim, quero dizer uma coisa bastante banal - o preenchimento automático melhora significativamente a qualidade de vida. Na maioria dos sistemas Unix, ele sai da caixa, mas se você conseguiu entrar na infraestrutura do Windows, recomendo fortemente mudar para o Powershell (se ainda não tiver feito) e instalar o posh-git , que fornece preenchimento automático para a maioria dos comandos e fornece um resumo minimalista no prompt:
Obrigado pela atenção; Desejo a todos um trabalho diário agradável e eficiente.
. :
[alias]
# `git sshow hack` - , "hack".
sshow = "!f() { git stash show stash^{/$*} -p; }; f"
# `git sapply hack` - "hack"
sapply = "!f() { git stash apply stash^{/$*}; }; f"
# `.git_dev`
dev = !git --git-dir=\"./.git_dev\"
# `.git/` `.git_dev/`
statys = "!f() { git status ; echo \"\n\" ; git dev status ; }; f"
#
findb = "!f(){ git branch -ra | grep $1; }; f"
# . `git hist -n 10`, 10
hist = log --pretty=format:\"%ad | %h | %an: \t %s%d\" --date=short -n5
# `git dist branch-name` branch-name
dist = "!git log --pretty=format:\"%ad | %h | %an: \t %s%d\" --date=short \"$(git rev-parse --abbrev-ref HEAD)\" --not "
# `exclude`
exclude = "!f() { vim .git/info/exclude; }; f"
# , `--assume-unchanged`
ignored = !git ls-files -v | grep "^[[:lower:]]"
# - , `git reset HEAD~1`
forward = "!f() { git log --pretty=oneline --all | grep -B1 `git rev-parse HEAD` | head -n1 | egrep -o '[a-f0-9]{20,}' | xargs git checkout ; }; f"