Git Pro

作者: Vicancy | 来源:发表于2013-07-22 16:33 被阅读0次

    Git Branching


    Tips & Tricks

    Git Tools
    • Interactive Staging
      git add -i/--interactive to select some files to stage/unstage
      git add -p/--patch to do partial-file staging
    Git Alias

    git config --global alias.ci commit
    git config --global alias.unstage 'reset HEAD --' : shortcut to unstage a staged file
    git config --global alias.last 'log -1 HEAD' : shortcut to get the last commit
    git config --global alias.visual '!gitk'
    add ! when call external command
    git config --global alias.sl '!"C:\Program Files\Sublime Text 2\sublime_text.exe" $*' : add sublime_text to git shortcut


    git remote

    • origin is the default name Git gives to the server you cloned from
    • -v : shows the URL that Git has stored for the shortname to be expanded to
    • can pull from many remote repositories, but only the origin remote is a SSH URL and can be pushed to.
    • git remote add [shortname] [url] -> git fetch [shortname]/git pull after git clone -> git push [shortname] [branchname] after git clone
    • git remote show [remotename] : show the remote repository
    • git remote rename [shortname] [newshortname] : rename a reference
    • git remote rm [shortname]: remove a reference to the remote repository

    undo things

    • git commit --amend : replace the previous commit
    • git reset HEAD <file> : unstage a staged file
    • git checkout -- <file> : unmodify a modified file dangerous

    git log

    • visual tool for git log: gitk
    • -p: shows the diff introduced in each commit
    • -2: limits the output to only the last two entries
    • --word-diff: get word diff instead of normal line by line diff
    • --stat: show abbreviated stats
    • --pretty=oneline/format --graph
    • --pretty=oneline/short/full/fuller
    • --pretty=format:""
    Option  Description of Output
    %H  Commit hash
    %h  Abbreviated commit hash
    %T  Tree hash
    %t  Abbreviated tree hash
    %P  Parent hashes
    %p  Abbreviated parent hashes
    %an Author name
    %ae Author e-mail
    %ad Author date (format respects the --date= option)
    %ar Author date, relative
    %cn Committer name
    %ce Committer email
    %cd Committer date
    %cr Committer date, relative
    %s  Subject
       ```
    > *author: the person who originally wrote the patch*
    > *Committer: a person who last applied the patch*
    
    
    ----------------------
    
    `git status`
    `git add` : a multipurpose command, use to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved
    ##### .gitignore
    * `#` as comments
    * end with `/` as directory
    * `!` to negate a pattern
    * `*`: 0+ characters; `?` 1 character; `[0-9]` & `[abc]`
    * `**/` as any directory
    
    `git diff` : see what changed but not yet staged
    `git diff --cache` or `git diff -staged`: see what staged but not yet committed
    `git commit -a` to skip staging area
    `git rm` : remove file from working directory and staging area
    `git rm --cached` : remove only from staging area
    `git mv` : can also do renaming
    

    相关文章

      网友评论

          本文标题:Git Pro

          本文链接:https://www.haomeiwen.com/subject/ywtftttx.html