📜 ⬆️ ⬇️

Git is enough to be (less) dangerous

image 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?

Good news! I wrote you this amazing Internet post. I hope I can smudge enough Git on your face to reduce the chance of doing something irreparable, and also reduce your fear of breaking something. This should also be enough to make the Git documentation a little more understandable; it is extremely thorough and deeply worked out and very stupid if you still have not read half.

I will try to present it briefly, but also so that it would be potentially useful to those people who have never experienced any version control at all , so 101 tips will be scattered everywhere. Do not be afraid! I don't think Mercurial users have a clue what a patch is.

What is going on here at all?


Git, , .

Git — DVCS, « », « » « », «» « ». ( . , . ?)

Git , , Linux. Linux — VCS, , , .. , .

Linux — , , Linux: . ( — , - . , .)

, «» , «», . - Wi-Fi- -, , . , - «- » . , , .

Git, , , «» , :

Git — .

, . - Git . : am, apply, format-patch, send-email, request-pull. Linux , , Git . man- Git Git, « ».

Git — , , .

Git, .


— . . « diff-».

, . , .

. , . ( «» — .) , , , . , , « Linux». « 3.0.5 Linux».

Git- «parent», , .

, -, — . ? (). (). «» « ».

. C , — B… , B, , , ?

. Git — , . , . :


A , . , — ! , , .

, . A, one. B, one two. , C, one two threeC. (Git , ; -. .)

Git , :

A---B---C

, -. , : A → B → C.

, , 8edc525cd8dc9e81b5fbeb297c44dd513ba5518e, 8edc52. , «», , SHA-1. , , SHA-1- , . ( .. — , , .. . Bitcoin!)

, . A, B A. B, . , , .


, Git: , . , . .

— Git . . , , , , , . () .

  1. , «» , , git checkout . «-, Git ». .. , .
  2. « ». , , .. , .

, !


Mercurial, Mercurial. , Mercurial , , .

Wi-Fi-. , , , , . , , .

, . , master ( -). , , --broadcom. , .

Git .

, , . , - ; . ; .

, — , - . (, . foo — 41- , .) , , , , , . , : - --broadcom, , .

Git , « ». , — , ; , - .

: . ! , — Linux , . …


«» «- », , Git — , - . , ; , - .

, , , «origin», . .

. . . — , . foo, Git origin/foo ( «-» ). .. , - git branch.

, .


, . , B. . ! !

, : A → B → C

: A → B → D → E → F

, Git, :

      C            --broadcom
     /
A---B---D---E---F  origin/master

, , . Linux — , , , .

, : , C F, , B. Git , . , , .

, Git , : C F.

      C-----------.    --broadcom
     /             \
A---B---D---E---F---G  origin/master

-, «» . .. , G — ; C F .

, , . , , G.


— , . , : . , « », , .

, ( ) , , . , , , , .



. . -?


. , , , Git.


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