Hands touching hands bring you closer to git

Foreword

  This paper describes the gitkey generation and configuration, basic commands include clone, add, commit, pull, pushand so on, conflict management, review and rollback version of history, and the submission of norms.

Key Generation and Configuration

  • Configure the user name and mailbox
//打开git bash 输入以下命令

//用户名,填你的名字全称 如:yaoxfly 方便识别
git config --global  user.name 'yaoxfly'
//邮箱,填你的常用邮箱,代码出错时会发邮件通知你
git config --global  user.email  '[email protected]'
  • Generate private and public keys
ssh-keygen -t rsa 并按回车3下

tips: Why press three, because there are tips you need to set a password, if you set a password each time you use git will be used, are generally not directly written as empty, hit enter just fine.

  • Private and public keys generated file name and path

  Private: id_rsathe public key: id_rsa.pub
The default folder you open git bashthe catalog, or in your home directory ~/.sshfolder

  • Configuring
    copy id_rsa.puball the contents of files attached to local needs, for example github, or code of public cloud configuration

tips: In the generation keybefore the git config --globalname and email must be set, otherwise each operation must fill in a user name and password, do not set a password on the keys, like the next step directly.

basis

clone (g financial items)

git clone  'xxxx'

add (new file)

git add .  // 匹配所有的文件, 提交被修改的和新建的文件,但不包括被删除的文件 
git add -u  // update tracked files  更新所有改变的文件,将修改的文件提交到暂存区。 
git add -A  // 是上面两个功能的合集(git add --all的缩写)

commit (submit)

  • submit
git commit -m  "添加你的注释,一般是一些更改信息"
  • Submit withdrawal
//仅仅是撤回commit操作,您写的代码仍然保留
git reset --soft HEAD^  

push (remote submission)

  • submit
git push origin master:master  
  • fatal: refusing to merge unrelated histories Refused to merge unrelated historical solution, forced to submit
git push origin master:master -f 
  • Submit shorthand
git push -u

tips: the main reason for the emergence of the problem lies with local storage and remote repository is actually two separate warehouses.

pull (Pull the newly merged)

  • git pull

  Command basically git fetchand the git mergecombination of commands, git fetch content from the specified remote repository, and then immediately try to merge into your branch is located.

  • git fetch [remote-name] (Lachine)

  This command accessing a remote repository, pull data from all of you have not. After the execution is complete, you will have to refer to all branches of the remote repository, you can merge or view at any time.
But note that git fetchit does not automatically merge or modify your current job. You must manually merge them into your work.

  • git merge [remote-name] (combined)

  Merge branch

  • to sum up

  Use git pullthe command to automatically fetch and then merge a remote branch to the current branch. (Equivalent to a plus merge execute fetch command) simpler, more convenient, more comfortable workflow.

branch (branch)

  • Create a new branch
 git branch newBranch
  • Switch to a new branch
 git checkout newBranch
  • Merge branch
git merge newBranch  
  • Deleted branches
 git branch -D newBranch

tips: before merging branches, must be switched to the desired branch merge, such as the main branch, then execution branches merge operation

Other commands

  • View submission history
git log
  • View current status
git status
  • Delete Cache
git rm -r --cached .

tips: application scenarios, such as invalid documents .gitignore ignore the situation, etc.

  • Modify the code associated with the local remote address
git remote set-url origin ssh://git@ip:端口/home/git/gitrepo/git.git 

tips: When the code base remote migration, you can use the current function

Gets the specified version of the source code for history

git clone http://XXXX/XX.git //克融项目
git log   // 查看commit历史,并找到需要的版本
git checkout '版本号' //获取

tips: Run git logcommand, after viewing commit to follow the hash value is the version number

Conflict Resolution

  • Version branch of the problem

  When submitting appear git repository:: Problem Description Your branch is up-to-date with 'origin / master'.

/*解决方案*/

//这时候我们就需要新建一个分支
 git branch newBranch  
//检查分支是否创建成功,前面的*代表的是当前你所在的工作分支
 git branch
//切换到你的新分支
 git checkout newBranch
//添加修改和新增的文件
 git add .
//提交到本地
 git commit -m "18.03.01"
//检查是否成功
 git status
//然后切换到主分支
 git checkout master 
//将新分支提交的改动合并到主分支上(合并前一定要切换到主分支)
 git merge newBranch   
// push代码了
 git push -u origin master
//删除这个分支
 git branch -D newBranch
  • Lead to conflict, garbled file

++<<<<<<< HEAD

++<<<<<<< new_branch

  These can be directly removed garbage, save and then submitted, some idemay suggest, and delete these garbled and other intelligence operations, such as vs code, coding artifact, my favorite, ha ha, a wave of strong push.

  • Tip: There are not consolidated in the warehouse of documents, you can not submit code.

   问题描述:committing is not possible because you have unmerged files

/*解决方案*/

//把你修改的文件一个个添加进去
git  add '文件名',
//提交本地
git commit -a -m  "备注信息" 
//提交远程
git push -u

Submit specifications

  • Specification
    git submission also regulate the industry to do better, with a reference value is Angularsubmitted.
<type>(<scope>): <subject> #header
// 空一行
<body>
// 空一行
<footer>

//中文释义
<类型>[可选的作用域]: <主题> 描述

[可选的正文]

[可选的脚注]

  • The main parameters
parameter Explanation Do you have to
type Submission Type true
scope Submit range of influence false
subject Submit a brief description of the purpose of false
header content true
  • type the following logo
    • feat: to add new features (feature)
    • fix: fix bug
    • docs: Documentation change (documentation)
    • style: code format changes
    • refactor: reconstruction of an existing function
    • build: change the build tools, such as
    • grunt replaced npm
    • revert: once on the revocation of commit
    • perf: Performance Optimization
    • test: increased testing
    • ci: changes related to the CI (continuous integration service)
    • chore: src modify or not modify the rest of the test, for example, build or assisting tool change process
    • del: delete a content

tips:

  1. If the type is a feat and fix, the commit will certainly appear in the Change log. Other special circumstances (docs, chore, style, refactor , test) is determined by you, not to put Change log, it is not recommended.
    ,
  2. When the time changes include major type and special type, uniform application of the main type.
Released seven original articles · won praise 108 · views 10000 +

Guess you like

Origin blog.csdn.net/u010716530/article/details/105369798