Git usage specification for enterprise-level development

 

[1] The significance of GIT usage specifications: improve the overall communication and operational efficiency of the team

【2】Specifications for use

  1. The projects that can be deployed independently use two main branches, master and dev. The master branch corresponds to the online version, and the dev branch corresponds to the development version. Only one master branch is needed for the work used as a dependent library. The master and dev branches can only be merged and submitted by the development team leader, and the rest of the staff need to work on their respective branches.
  2. GIT commits try to follow a single commit. The code is a modification of a complete but minimal impact function. Do not mix and submit changes to several functions.
  3. The first line of a GIT comment must start with a lowercase task or bug, followed by the ID of the corresponding task or bug on Zen Tao, followed by a half-width colon. The comments should at least clearly state the modifications made this time and the effects achieved, the more detailed the better. The first line of comments should be between 15-120 characters. If the comment length is more than 120 characters, write the summary information on the first line, leave a blank line, and then write the detailed information, similar to the mail format.
  4. The branch is best pulled from the official version of the tag, and the official version of the tag is viewed. Branch names must have a clear meaning to facilitate management. After the function goes online, the corresponding branch should be deleted in time. The recommended naming method of the branch name is: start with user/, add task or bug, and add the id of the corresponding task or bug on Zen Tao. It is mandatory to start with user/.
  5. If the submission is unsuccessful due to comments, please follow the instructions of Rewriting Last Comment and Rewriting Previous Comments of Common Actions to rewrite the comment

[3] Learning materials: Pro Git Chinese version

[4] Environment configuration:

 

  • Install GIT according to the  GIT installation tutorial
  • Right-click under any folder (Windows), click git bash here to open the git command line, and execute the following command:
    git config --global user.name "Developer's Chinese name"--git config --global user.name " Marklin"
  • git config --global user.email "developer's registered email" --git config --global user.email [email protected]
  • Generate the public key locally. On the git command line, execute the following command:
    ssh-keygen -C "developer's registered mailbox" --ssh-keygen -t rsa -C "[email protected]" The mailbox here must be the same as the first one The email address set in the second step is the same. After entering the command, the subsequent prompt input is directly pressed Enter, and the default value can be used.
  • The file {user.dir}/.ssh/id_rsa.pub will be generated after this operation
  • Log in to Github and log in. Click on the username in the upper right corner->settings->SSH Public Keys, copy the content in id_rsa.pub, and click Add.

【5】Common operations

1. Alias ​​configuration (basic for next steps)

git config –global alias.st status #设置完后 git st = git status
git config –global alias.ci commit
git config –global alias.co checkout
git config –global alias.br branch

2. Clone (download) project

git clone project-url #Follow the prompts on gerrit

3. Check the status

git status #The most commonly used operation will give clear prompts

4. View branch (tag)

git br #View local branches, the current branch color is green, there is a *
git br -a #View all branches, the remote branches can be used by users to switch branches

5. Switch branches

git co branch-name #branch-name refers to the existing branch name

6. Create a new branch

git br branch-name #Create a new branch from the current commit of the current branch
git co branch-name #Switch to the new branch, and will carry uncommitted changes when switching

7. Pull remote modification

git pull # will pull information including tags

8. Submit changes

git add . –A #Add all changes in the current directory to the cache
git ci #Commit changes from the cache to the local library

9. Tagging

git tag tag-name # put a tag on the current commit
git tag tag-name commitId # put a tag on the commitId

10. Push changes

git push #Push the changes of the current branch to the remote branch
git push --tags #Push the current branch and all new tags to the remote server

11. Merge branches

git co master #Switch the current branch to master
git merge dev #Switch the modification of the dev branch to master

12. Delete remote branches or tags

git push origin --delete branch-name #Delete remote branch, requires gerrit permission
git push origin --delete tag tag-name #Delete remote tag, requires gerrit permission

13. Rewrite the last comment

#If you find that the comment is wrong immediately after submitting, you only need to rewrite the last comment, in these commands;
git ci –amend

14. Rewrite the first few comments

慎用git reset操作,尤其是reset已经推送到远程服务器上的commit。
如果发现之前的几次提交注释写错了,找到写错注释的前一个commitId,假设为abcdefg,执行
git reset –-soft abcdefg #类似将abcdefg之后的git ci命令取消,并且将git add命令合并得到的结果。然后执行
git ci #和正常提交一样写注释。

15.取消发布(慎用!配合操作!)

场景:1.0.0已经发布,计划功能F1,F2,F3,以及不过B1,B2需要在1.1.0发布,
分支F1,F2,F3,B1,B2都已经合到dev上了,并且已经发布了1.1.0-b1,1.1.0-b2两个beta版。
此时F1功能因种种原因需要取消,此时需要执行如下操作:

 

git co dev #Switch to the dev branch.
git tag -d 1.1.0-b1 #Delete local tag 1.1.0-b1
git tag -d 1.1.0-b2 #Delete local tag 1.1.0-b2
git reset –hard 1.0.0 #Undo and restore all merges dev to the state of 1.0.0.
git merge F2 #re-merge F2
git merge F3 #re-merge F3
git merge B1 #re-merge B1
git merge B2 #re-merge B2
git tag 1.1.0-b1 #re-tag 1.1.0-b1
git push origin –delete tag 1.1.0-b1 #Delete remote branch 1.1.0-b1
git push origin –delete tag 1.1.0-b2 #Delete remote branch 1.1.0-b2
git push -f origin dev #Use local dev branch to force update remote dev branch
git push -tags #Push the local tag to the remote server

[5] GIT work flow chart

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326086065&siteId=291194637