zoukankan      html  css  js  c++  java
  • git命令笔记2

    git乱码解决:在Ubuntu下,git status时,中文文件名乱码类似“274232350256256346200273347273223.png”,修改配置即可"git config --global core.quotepath false"

    (参考:http://blog.zengrong.net/post/1249.html)

    配置全局.gitigonre
    添加文件~/.gitignore_global,然后在~/.gitconfig里加入:

    [core]
        excludesfile = ~/.gitignore_global  
    1.
    # 忽略所有后缀为.a的文件
    *.a
    # 不忽略lib.a(相对于上面的)
    !lib.a
    # 只忽略根下的TODO,不递归到子目录
    /TODO
    # 忽略所有build/下的文件
    build/
    # 忽略类似doc/notes.txt,但不包括doc/aa/bb.txt
    doc/*.txt
    # 忽略所有doc文件夹下的txt文件,递归到子目录
    doc/**/*.txt
    
    2. Short Status
    $ git status -s
    M README
    MM Rakefile
    A lib/git.rb
    M lib/simplegit.rb
    ?? LICENSE.txt
    
    New files that aren’t tracked have a ?? next to them, new files that have
    been added to the staging area have an A, modified files have an M and so on.
    
    3. 
    git diff 与已经commit的比较
    git diff --staged 已经add的比较与已经commit的比较
    git diff --cached 与staged同义
    
    4.
    git rm 2.txt 会真的删除文件2.txt(需要commit)
    git rm --cache 2.txt 只是移除git的管理状态,不会删除物理文件
    git rm log/*.log 删除log文件夹中的.log文件,注意这里的*中的是对*进行转义
    git rm *~
    
    5.
    git mv a.txt b.txt
    =
    mv a.txt b.txt
    git rm a.txt
    git add b.txt
    (这种3行命令的方式,git依然能够理解是在进行重命名操作)
    
    6.
    git log 查看log
    git log -p 查看每次提交的变化
    git log -p -2 查看最近两次提交的变化
    git log --stat 查看提交的统计信息(如下:)
        README             | 6 ++++++
        Rakefile           | 23 +++++++++++++++++++++++
        lib/simplegit.rb   | 25 +++++++++++++++++++++++++
        3 files changed,54 insertions(+)
    git log --pretty=oneline
    git log --pretty=format:"%h - %an, %ar : %s"
        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
    git log --pretty=format:"%h %s" --graph //a nice little ASCII graph
    git log --since=2.weeks
    
    7. Undong Things
    git commit --amend //场景:刚已经进行了提交,但是可能有文件忘记了add
        或者还有什么需要修改后在这次提交中提交的,可以使用--amend,这样可以将这些修改补充到刚才的提交中
        git add 1.txt
        git commit -m 'hahh, a commit'
        #oh no, a file named 2.txt is forgetten. but it should be committed in this commit
        git add 2.txt
        git commit --amend
        #hahah, 'amend' is useful.
    
    git reset HEAD test.txt 撤销add
    git checkout -- test.txt 撤销修改(慎用!会使修改丢失)
    
    8.
    git clone https://github.com/schacon/ticgit
    git remote
    git remote -v
    git remote add pb https://github.com/paulboone/ticgit
    git fetch pb 
    git remote show origin (see much more information)
    git remote rename pb paul 重命名
    
    9.
    Git uses two main types of tags: lightweight and annotated.
      A lightweight tag is very much like a branch that doesn’t change – it’s just a pointer to a specific commit.
      Annotated tags, however, 【are stored as full objects in the Git database】. They’re checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.
    
    git tag
    git tag -l 'v1.8.5*'
    
    git tag -a v1.4 -m 'my version 1.4' 添加Annotated tag
    git show v1.4
    
    git tag v1.4.1-lw 添加Lightweight Tags
    git show v1.4.1-lw
    
    git tag -a v1.2 9ab3ef34  根据某次提交记录打tag
    
    git push origin v1.2 推送tag(git默认是不会推送tag的)
    git push origin --tags 推送所有tag
    
    git checkout -b version2 v2.0.0 根据标记创建分支
    
    10. 给git命令设置别名
    git config --global alias.unstage 'reset HEAD --'
    git unstage fileA
    等效于:
    git reset HEAD fileA
    
    git config --global alias.last 'log -1 HEAD'
    use: git last

    参考:

    1. git pro

  • 相关阅读:
    用SQL SERVER取分组数据第一条:查出每个班级的成绩第一名
    [转]spring beans.xml
    [转]为什么要使用框架
    MySQL 5.6 for Windows 解压缩版配置安装
    [转]hql 语法与详细解释
    [转]slf4j + log4j原理实现及源码分析
    [转]最详细的Log4j使用教程
    yii2 checkbox 的使用实例
    Magento Order 状态详解
    yii2 设置多个入口文件
  • 原文地址:https://www.cnblogs.com/liqipeng/p/4592184.html
Copyright © 2011-2022 走看看