git入门-----其它的常用命令(config、cherry-pick)

来源:互联网 发布:常德跑胡子源码 编辑:程序博客网 时间:2024/06/06 12:15
1、git config (整理的网上的自己还没有验证)
     git config 用于配置git 对应的配置文件有三个位置,对应于不同的覆盖。
     1)、/etc/gitconfig 文件:
        包含了适用于系统所有用户和所有库的值。如果传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。 
     2).、~/.gitconfig 文件 :具体到你的用户。
         你可以通过传递--global 选项使Git 读或写这个特定的文件。
      3)、位于git目录的config文件 (也就是 .git/config) :
        无论你当前在用的库是什么,特定指向该单一的库。比如你在当先的git仓库下,那么它就是对当前的git仓库的修改
       不加任何参数或者--local的时候 
       注意:每个级别重写前一个级别的值。因此,在.git/config中的值会覆盖了在~/.gitconfig,它会覆盖在/etc/gitconfig中的
                   同一个值。当没有的时候就会去上级找然后使用。
      常用的配置:
            当你安装Git后首先要做的事情是设置你的用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信
       息。它被永远的嵌入到了你的提交中:
  1.   $ git config --global user.name Joey
  2.   $ git config --global user.email zhaojoeyuan@163.com
         为当前的用户设定,当你想在某个仓库中使用特殊的,你只需要再设置一遍,不带--global即可。
      常看当前的所有设置 git config -l:
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ git config -l
  3. \core.symlinks=false
  4. core.autocrlf=true
  5. core.fscache=true
  6. color.diff=auto
  7. color.status=auto
  8. color.branch=auto
  9. color.interactive=true
  10. help.format=html
  11. http.sslcainfo=D:/git/Windows/Git/mingw64/ssl/certs/ca-bundle.crt
  12. diff.astextplain.textconv=astextplain
  13. rebase.autosquash=true
  14. user.name=Joey
  15. user.email=zhaojoeyuan@163.com
  16. push.default=simple
  17. core.editor=vi
  18. core.repositoryformatversion=0
  19. core.filemode=false
  20. core.bare=false
  21. core.logallrefupdates=true
  22. ......
     还有比较常用的属性如:
     --system, --global, --local   --local:是默认的哦.
     git config [--global] options  value
     core.editor=gedit  : 用于设置默认的编辑器
     push.default=simple :用于设置默认的push方式
    --get :用于获取
             git config --get core.editor
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ git config --get core.editor
  3. vi
            git config --global --get user.name
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ git config --get user.name
  3. Joey
           --unset 删除 :git config --unset user.name 删除某个配置

2、git cherry-pick。
     完整命令:git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] [-S[<keyid>]] <commit>…
     git cherry-pick : 对已经提交的commits进行再次的提交. 可以是一个也可以是多个。
     此处我用了一个不会产生冲突的,来理解这个命令,自己建立了一个new.txt文件
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ vi new.txt
  3. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  4. $ git status
  5. On branch master
  6. Your branch is ahead of 'origin/master' by 1 commit.
  7. (use "git push" to publish your local commits)
  8. Untracked files:
  9. (use "git add <file>..." to include in what will be committed)
  10. new.txt
  11. nothing added to commit but untracked files present (use "git add" to track)
  12. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  13. $ git add .
  14. warning: LF will be replaced by CRLF in new.txt.
  15. The file will have its original line endings in your working directory.
  16. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  17. $ git commit
  18. [master 52d0d56] Joey 测试为了cherry-pick的命令 哈哈哈哈哈啊哈哈哈哈哈啊哈
  19. warning: LF will be replaced by CRLF in new.txt.
  20. The file will have its original line endings in your working directory.
  21. 1 file changed, 1 insertion(+)
  22. create mode 100644 new.txt
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ git log
  3. commit 52d0d56d7a70181672cbf78149f60a50ad93add9
  4. Author: Joey <zhaojoeyuan@163.com>
  5. Date: Tue Apr 18 20:38:29 2017 +0800
  6. Joey
  7. 测试为了cherry-pick的命令
  8. 哈哈哈哈哈啊哈哈哈哈哈啊哈
  9. commit dc67406bf27de952d792cde3f6387d12dcca7544
  10. Author: Joey <zhaojoeyuan@163.com>
  11. Date: Mon Apr 17 23:17:10 2017 +0800
  12. checkout
          提交上去后我们切换分支,去另一个分支,打算把前面的提交cherry-pick上去。
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  2. $ git branch
  3. joey/master
  4. local
  5. * master
  6. new
  7. next
  8. test
  9. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (master)
  10. $ git checkout test
  11. Switched to branch 'test'
  12. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  13. $ ls
  14. Test.txt
  15. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  16. $ git log -2
  17. commit e4b44b46e2b55e07ef0b69f440a57ab72f666826
  18. Author: zhaoJoeyuan <zhaojoeyuan@163.com>
  19. Date: Mon Apr 17 22:38:52 2017 +0800
  20. Update Test.txt
  21. commit ee244d06b0221853e1711bb453d5bcaada488747
  22. Author: zhaoJoeyuan <zhaojoeyuan@163.com>
  23. Date: Mon Apr 17 22:32:24 2017 +0800
  24. Update Test.txt
  25. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  26. $ git cherry-pick 52d0d56d7a70181672cbf78149f60a50ad93add9
  27. [test 81dcaa7] Joey 测试为了cherry-pick的命令 哈哈哈哈哈啊哈哈哈哈哈啊哈
  28. Date: Tue Apr 18 20:38:29 2017 +0800
  29. 1 file changed, 1 insertion(+)
  30. create mode 100644 new.txt
  31. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  32. $ ls
  33. new.txt Test.txt
          假如不知道前面提交的id就用git reflog来查看,此处可以看到成功的把master分支上的cherry-pick到了这个分支上。
    注意的是commitid是不一样的,用来表示唯一的一次提交。在实际开发中可能还需要修改提交的message信息,那么你
   就用git commit --amend来修改即可
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  2. $ git commit --amend
  3. [test 70e1cdb] Joey 测试为了cherry-pick的命令 哈哈哈哈哈啊哈哈哈哈哈啊哈 修改messgae信息.
  4. Date: Tue Apr 18 20:38:29 2017 +0800
  5. 1 file changed, 1 insertion(+)
  6. create mode 100644 new.txt
  7. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  8. $ git log -2
  9. commit 70e1cdb6b8ce366eb004d0e900e1e443089f96b2
  10. Author: Joey <zhaojoeyuan@163.com>
  11. Date: Tue Apr 18 20:38:29 2017 +0800
  12. Joey
  13. 测试为了cherry-pick的命令
  14. 哈哈哈哈哈啊哈哈哈哈哈啊哈
  15. 修改messgae信息.
         还可以修改作者,工作的时候有时候当前的patch并不是你,你就需要修改了,注意name的格式。
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  2. $ git commit --amend --author="zhaoyuan <zy782234027@qq.com>"
  3. [test 083f58f] Joey 测试为了cherry-pick的命令 哈哈哈哈哈啊哈哈哈哈哈啊哈 修改messgae信息.
  4. Author: zhaoyuan <zy782234027@qq.com>
  5. Date: Tue Apr 18 20:38:29 2017 +0800
  6. 1 file changed, 1 insertion(+)
  7. create mode 100644 new.txt
  8. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  9. $ git log -2
  10. commit 083f58fd2cce4310d041f575d9c80cb20511923a
  11. Author: zhaoyuan <zy782234027@qq.com>
  12. Date: Tue Apr 18 20:38:29 2017 +0800
  13. Joey
  14. 测试为了cherry-pick的命令
  15. 哈哈哈哈哈啊哈哈哈哈哈啊哈
  16. 修改messgae信息.
          当一切都符合要求后你把这次提交push到远程版本库,或者gerrite上面即可。   有冲突的时候就和平常一样解决冲突
    即可。  当执行完 cherry-pick 以后,将会 生成一个新的提交。git commit -c id  :id是cherry-pick的id.
          git cherry-pick  -x <commit id>:这个cherrypick会保留原提交者的信息,比如原作者。不过不知道commiter变不变?
   实际工作的时候要注意了。
         git fetch ssh://xp022430@review.sonyericsson.net:29418/platform/packages/apps/Nfc refs/changes/13/1788013/1 && 
git cherry-pick FETCH_HEAD :从gerrite上面复制下来的cherry-pick的命令是这样的,先fetch,然后把fetch的远程的提交
ID,cherr-pick到本地。然后你自己看看需不需要修改message信息,author等等的信息。自己改即可。
     
0 0
原创粉丝点击