Getting started with git -- other common commands (config, cherry-pick)

Keywords: git Windows SSL ssh

1. git config (self not verified on organized web)
The git config configuration file used to configure git has three locations corresponding to different overrides.
(1), /etc/gitconfig file:
Include values that apply to all users and libraries of the system.If the parameter option'--system'is passed to git config, it will explicitly read and write the file.(
2).,~/.gitconfig file: specific to your users.
You can make Git read or write this specific file by passing the--global option.
3), config file located in Git directory (that is.git/config):
Whatever library you are currently using, point specifically to that single library.For example, if you are in the first git repository, it is a modification to the current git repository
* without any parameters or when --local
Note: Each level overrides the value of the previous level.Therefore, the value in.git/config will override ~/.git config, which will override in/etc/git config
The same value.When not, go to your superior and use it.
Common configurations:
The first thing you need to do when you install Git is set up your user name and e-mail address.This is important because the letter is used every time a Git submission is made
Info.It is permanently embedded in your submission:
  1.   $ git config --global user.name Joey
  2.   $ git config --global user.email zhaojoeyuan@163.com
For current users, when you want to use something special in a warehouse, you just need to set it up again without the--global s.
* See all current settings git config-l often:
  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. ......
There are also more common attributes such as:
--system, --global, --local--local: is the default.
     git config [--global] options  value
core.editor=gedit: Editor to set default
push.default=simple: used to set the default push mode
--get: used to 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 Delete: git config --unset user.name Delete a configuration

2,git cherry-pick.
Complete command: git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] [-S[<keyid>] <commit>...
git cherry-pick: Submit commits that have already been submitted again. Can be one or more.
Here I used a non-conflicting command to understand the command and created a new.txt file of my own
  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 : Test forcherry-pickCommand of Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha
  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. Test forcherry-pickCommand of
  8. Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha
  9. commit dc67406bf27de952d792cde3f6387d12dcca7544
  10. Author: Joey <zhaojoeyuan@163.com>
  11. Date: Mon Apr 17 23:17:10 2017 +0800
  12. checkout
After submitting, we switch to another branch, intending to put the previous submission cherry-pick on.
  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 : Test forcherry-pickCommand of Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha
  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
If you don't know the previously submitted id, use git reflog to view it, here you can see that cherry-pick ing on the master branch succeeded.
Notice that commitid s are different and represent the only submission.You may also need to modify the submitted message information during actual development, so you
) Just use git commit --amend to modify it
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  2. $ git commit --amend
  3. [test 70e1cdb] Joey : Test forcherry-pickCommand of Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha modifymessgaeinformation.
  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. Test forcherry-pickCommand of
  14. Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha
  15. modifymessgaeinformation.
You can also modify the author. Sometimes the current patch isn't you at work, so you need to change it. Note the format of the name.
  1. Administrator@9GPBSPCCTFQXEUX MINGW64 /e/gits/RemoteForTest (test)
  2. $ git commit --amend --author="zhaoyuan <zy782234027@qq.com>"
  3. [test 083f58f] Joey : Test forcherry-pickCommand of Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha modifymessgaeinformation.
  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. Test forcherry-pickCommand of
  15. Ha Ha Ha Ha Ha Ha Ha Ha Ha Ha
  16. modifymessgaeinformation.
You can submit this push to a remote repository or gerrite once everything has been met.Resolve conflicts as usual when there are conflicts
You can.When a cherry-pick is executed, a new submission is generated.Git commit-c id: ID is cherry-pick ID.
git cherry-pick-x <commit id>: This cherry pick retains information about the original submitter, such as the original author.But don't know if commiter stays the same?
Be careful when you are actually working.
         git fetch ssh://xp022430@review.sonyericsson.net:29418/platform/packages/apps/Nfc refs/changes/13/1788013/1 && 
git cherry-pick FETCH_HEAD: The command for cherry-pick copied from gerrite is as follows: fetch first, then submit fetch remotely
ID, cherr-pick to local.Then you see for yourself that you don't need to modify message information, author, and so on.Change it yourself.

Posted by HGeneAnthony on Sat, 06 Jul 2019 10:05:10 -0700