Do you just hate git ? You're absolutely happy with Mercurial (or, uh, with Subversion), but once a month you have to bravely encounter Git, because everyone, even his damn dog, now uses GitHub? You are plagued by vague suspicions that half of all Git commands will in fact remove all your work forever, but you don’t know what exactly and don’t want to spend three weeks delving into the documentation?am, apply, format-patch, send-email, request-pull. Linux , , Git . man- Git Git, « ».one. B, one two. , C, one two three — C. (Git , ; -. .)A---B---C
8edc525cd8dc9e81b5fbeb297c44dd513ba5518e, 8edc52. , «», , SHA-1. , , SHA-1- , . ( .. — , , .. . Bitcoin!)git checkout . «-, Git ». .. , .master ( -). , , --broadcom. , .foo — 41- , .) , , , , , . , : - --broadcom, , .foo, Git origin/foo ( «-» ). .. , - git branch. C --broadcom
/
A---B---D---E---F origin/master
C-----------. --broadcom
/ \
A---B---D---E---F---G origin/master
git clone github.com/funny_guy/just_for_lulz_code just_for_lulz_code.git pull origin master, . , .git pull --ff-only origin master, - , « ». , . , A, A → B → C, , Git , .git log . .git log --oneline --graph --decorate . tig, , Enter , .git log --follow , ( ). --follow - , , .
git show , . git show : .
,
git status : , ..
git branch , , , . git checkout -b origin/master, , origin/master, .
git checkout . , , " HEAD". , HEAD ( , , ) , , , .
git add Git , , .
git rm Git, , . ( . Git , . rm, git commit -a .)
git mv Git, . (, Git ; , .)
git commit -a , , , Git.
- Git : , "index", "staging area", "cache". ( .) , . git add , ( , ) git status. . git commit -a, . , , . ( , git add -p.) git commit -a, . , git add; git commit.
. , -?
, . Git - . " " , , . ( GitHub , , , GitHub .)
git push . GitHub, "origin", , , , master . git push origin master .
git push, - . , , : .
, , ( ) , - . Git " ; --". git status, . .
- :
<<<<<<< HEAD
-,
=======
-, -
>>>>>>> origin/master
( diff3 ; .)
, , Git . , HEAD - , (HEAD - , ); - , .
, "" - - , , - . git add, Git, . git add, git commit, .
, - , , , . git merge --abort, , , master, .
:
- , . Git !
- , - , . , Git . , , , -, , ; ,
git rm. - -
git mergetool, , . vimdiff, , . .
- ! ?!
git - Stack Overflow . ! - .
, git reset --hard, . , , , .
- , git rebase git cherry-pick , git status , , , git rebase --abort , .
, - , git reflog.
git show .
,
, , . .
HEAD - - , , .
. man gitrevisions . :
foo^ - () foo. HEAD^. , ^ - .foo..bar - , foo, bar .
man gitrevisions, 80% , .
, , , , . --, ", - ".
.gitconfig, , . Git, man git-config, - .
Git git config foo.bar.baz. git config --global foo.bar.baz value, --global ~/.gitconfig ( , ), .git/config ( ).
~/.gitconfig, , INI-, , . , .
, -,
, Git , , Git , , . (, , GitHub , -.)
Git , , . " " /etc/passwd ( ), (, , , 1983 ). , , - .
.gitconfig :
[user]
name = Eevee (Alex Munroe)
email = eevee.git@veekun.com
.
- ,
, git status , - . - , .
, , , .gitconfig Git-, . Git.
. , , , .gitconfig.
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
.gitconfig :
[merge]
conflictstyle = diff3
, :
<<<<<<< HEAD
,
=======
,
>>>>>>> master
. , , .
diff3, :
<<<<<<< HEAD
,
|||||||
,
=======
,
>>>>>>> master
, . , . , , , -.
, ,
Git - . Git - .
, Git - , rm ls. , Git , , - . , : Git , 100% - , . , .
, , , :
- . ( ). , ( "" ). ( ).
- , . "" . . ( : - , , .)
- , . ( , !) , GitHub " GitHub":
gh-pages , . - . ; . , .
- Git , . Git.
.keep - . - , , . , , ,
git commit, - -C, , , - . -m, , .
,
Git - , , , Git, , . ls rm , , , Git , .
, , , , , .
git rm
, . Git , , , .
git checkout
git checkout , , - . git checkout [commit] -- <files...>, . - , , ( ), git checkout -- .
, , , . , , .
-p, . ( -p, git add, . .)
git reset
"Reset" - . , .
git reset --hard <files...>, , git checkout. - "" . , , .
- git stash, -, . , git stash list, , - , git stash apply.
git rebase
, . , "rebase", , .
"Rebase" - . , . git rebase .
, A → B → C, C - , B - origin/master. ... , ! D . :
.---C master
/
A---B---D origin/master
... . , "" . Git C, D, ( ), . C, , . C'. ( - ; , "", , .)
:
.---C
/
A---B---D origin/master
\
.---C' master
B, , D. , . .
, origin.
, C , . Git 30 ( git reflog), , , .
, . , , - - C, , C', . , C C' , , . git rebase, , .
, : C , C , C, .. , , , , Git.
, . "", - "". - , , . Git, "", - ""! git checkout --ours, "" "", git status. , , , !
, git rebase --abort. , , @{1}, " , , ". git reset --hard , , , .
--force
git push . - , .. . , , , . , , , , , Git 2.0 --force-with-lease, , , .
, ..
Git - , . , . - , . Git, , . , , , .
-, -, , . ( , . , .)
. , , - , , , -. , !
, -
Git - , , ... .
, , . , . , ! - , , Git , , - , , .
- , , - : git status , , .
,
Git , Git ; - .
, , - , , Git !
Git, , . GitHub.
P.S.
- (Alex Munroe aka Eevee).
- Indexator.
CC-BY.
Source: https://habr.com/ru/post/268951/
All Articles