Git source code management, git-man operation and remote operation github repository

Copyright: Changan white https://blog.csdn.net/weixin_44074810/article/details/91354094

Git

1. git
work area, staging area and warehouse district

Workspace: For add, modify, delete unneeded files, have occurred in the work area

Staging Area: staging area refers to the completion of the operation in the work area to store small stage, it is part of the repository

Warehouse District: Warehouse District, represented a complete personal development of the small stage

Note:
Each version 1. The warehouse area is recorded and can be viewed fallback
2. But in the version submitted to the staging area once it is no longer

A, Git single local warehouse operations

  1. 安装git
    sudo apt-get install git

  2. Check the installation results git
    git

  3. Create a project
    to create a folder on the desktop, the project represents the work
    mkdir test

  4. Create a local warehouse
    ① into the test, and create a local repository .git
    cd Desktop / the Test /
    git the init

This will create a new .git ② warehouse is empty warehouses

③ into the path of the file to be displayed, ctrl + h, then displays hidden files

  1. Configuring Personal Information
    git config user.name 'Joe Smith'
    git config user.email '[email protected]'

  2. New py file
    test which is created in the project file login.py file for version control demo
    cd Desktop / test /
    Touch login.py ,

  3. View file status
    git status

① Red indicates a new file or newly modified, both in the work area.
② green indicates that the file in a temporary area
③ new login.py files in the workspace, you need to add to the staging area and submitted to the warehouse district

  1. Add the workspace files to the staging area
    ① add all project files
    git add.
    Or
    ② add the specified file
    git the Add login.py

After the file name is added to the staging area will turn green

  1. The documents submitted to the staging area to the warehouse district
    commit generates a version history
    behind -m version with descriptive information

git commit -m 'version descriptor'

  1. Then you can edit the code login.py
    VI login.py / Vim login.py
    to be add and commit operation code created

Tip: Add and submit merge command, this is the git add and git commit -m 'version of the description' synthesized a code.
Git the commit -AM "version Description"

Code submitted twice, there will be two versions of records

11. The version history
git log
or
git reflog

git reflog can view all records all operating branches (including operating and reset the commit),
including the commit record has been deleted, git log can not look at the commit record has been deleted

12. fallback version of
Option One:
① the HEAD represents the current latest version
② HEAD ^ represents the most current version of the previous version
③ HEAD ^^ represent the most current version of the first two versions, and so on ...
④ the HEAD ~ 1 represents the current date version of the previous version
⑤ HEAD ~ 10 indicates that the current version of the latest version of the top 10, and so on ...

git reset --hard HEAD^

Option Two: When the alternative version of a very long program

通过每个版本的版本号回退到指定版本

  git reset --hard 版本号

When the rollback error before you can use the version number of git reflog view,
then use the version number of the previous version plus git reset --hard to return back

13. undo changes

  1. Revoked only in the work area, staging area codes, area code repository can not be undone

  2. Warehouse District revocation code is equivalent to rollback version of the operating

① revocation of the work area codes

新加代码num3 = 30,不add到暂存区,保留在工作区

git checkout 文件名

① revocation staging area codes

新加代码num3 = 30,并add到暂存区

1. 第一步:将暂存区代码撤销到工作区
git reset HEAD  文件名
2. 第二步:撤销工作区代码
git checkout 文件名

Two, Git remote repository Github
Github Web site as a remote code warehouse operations and warehouse as native code, but warehouse location is different!

Ready Git source code repository https://github.com/

Create a remote repository
1. Log in Register Github
https://github.com/
follow the steps like

Configuring SSH

Select SSH operation
if a computer needs to interact on Github and warehouse, then they would have to add this computer's SSH public key to this Github account

1. Configure inlet SSH public key

2. Generate SSH public
use: SSH-keygen -t RSA -C "[email protected] " Enter your mailbox qiruihua can be replaced in the terminal or user name

3. Configure SSH Public Key

  1. Use git clone command to clone file

  2. In the push to change the code uploaded to a remote repository

Cloning project

1. cloning the remote repository command
cd Desktop / Manager /
git clone https://github.com/qruihua/info.git
behind clone path is re-created a good remote repository to copy the current repository path

2. cloning a remote repository to local

3. After the successful cloning of view files

4. Configuration identity information
CD Desktop / Manager / info /
Git config the user.name 'manager'
Git config user.email '[email protected]'

5. Create Project

6. push the project to the remote repository

  # 工作区添加到暂存区
  git add .
  # 暂存区提交到仓库区
  git commit -m '立项'
  # 推送到远程仓库
  git push

You need to set the account and password in a push when the password is github account and password

At this point the remote repository to see whether to create successful
Tip:
If you need to push each set account and password, you can set a password to remember

设置记住密码(默认15分钟):
git config --global credential.helper cache
如果想自己设置时间,可以这样做(1小时后失效):
git config credential.helper 'cache --timeout=3600'
长期存储密码:
git config --global credential.helper store

Multiplayer Cooperative Development: Suppose there are two people, one manager, one is Joe Smith

  1. Now create a remote warehouse

  2. And then cloned into a remote warehouse manager in local

  3. And then cloned into the local remote warehouse in John's

  4. Manager Joe Smith and configuration identity information

  5. Managers then write code uploaded to the remote repository git push command in the code editing interface

  6. Joe Smith in remote code synchronization using the git pull command, and then upload it to write in the remote repository.

  7. Warehouse manager and then Remote code synchronization down in writing. And then uploaded to a remote repository

  8. Repeat is so

  9. to sum up:

    To use the command git repository operation, you need to enter the inside of the warehouse
    to the synchronization server code is executed: git pull
    local repository recorded version on the implementation of: git commit -am 'version of the description'
    push code to the server to execute: git push
    before the first editing code pull, edit and then finished commit, is the final push push

Code Violation
1. Tip: multiplayer collaborative development, the code can not avoid situations of conflict will be
2 reasons: people modify the same file at the same time
3. HAZARDS: will affect the normal development progress
4. Note: Once the code conflict It must be resolved to do follow-up development

A case is assumed:
1. Zhang login.py first edit file code
into the local repository Zhang: cd Desktop / zhangsan / info
pull server latest code: git pull
edit the code: num3 30 =
local repository record version: git commit -am ' third variable '
push server repository: git push

2. Manager without first remote synchronization code repository and then directly after the upload file code editing login.py

进入经理本地仓库:cd Desktop/manager/info/
编辑代码:num3 = 300
本地仓库记录版本:git commit -am '第三个变量'
推送到服务器仓库:git push

The above operation will be code violations
manager must first pull

3. resolve conflicts

原则:谁冲突谁解决,并且一定要协商解决
方案:保留所有代码 或者 保留某一人代码
解决完冲突代码后,依然需要add、commit、push

supplement:

一、容易冲突的操作方式
    1. 多个人同时操作了同一个文件
    2. 一个人一直写不提交
    3. 修改之前不更新最新代码
    4. 提交之前不更新最新代码
    5. 擅自修改同事代码

二、减少冲突的操作方式
    1. 养成良好的操作习惯,先pull在修改,修改完立即commit和push
    2. 一定要确保自己正在修改的文件是最新版本的
    3. 各自开发各自的模块
    4. 如果要修改公共文件,一定要先确认有没有人正在修改
    5. 下班前一定要提交代码,上班第一件事拉取最新代码
    6. 一定不要擅自修改同事的代码

Tag
when a certain big version, you need to make a label
function:
recording large version
backup large version of the code

Simulation manager playing tag
1. Go to a local warehouse manager info
cd Desktop / Manager / info /

2. tagging manager locally
git tag -a tag name 'Tag Description' -m
Example:
git tag -a -m V1.0 "Version 1.0 '

3. Push the label manager to a remote repository
git push origin label name
Example:
git push origin v1.0

Added: Delete local and remote tag

# 删除本地标签
  git tag -d 标签名
  # 删除远程仓库标签
  git push origin --delete tag 标签名

Branch

Role:
to distinguish between production code, and the code development environment
new features or technological research problems
solved online bug

Features:
project development, including public branch master, dev
branch master is the default branch for release when needed release to dev branch into the master branch
branch dev branch is used to develop and complete the development stage of the code, we need to merged into the master branch

Simulation Manager branching operation
1. To enter into the local repository manager info
CD Desktop / Manager / info /

2. Review the current branch
git branch
when not create additional branches, only the master branch

3. Manager to create and switch to dev branch
git checkout -b dev

4. Set the specified remote local branch track branches (the branch to remote push)
Git Push -u dev Origin

5. edit code branch manager dev

6. dev branch source code management: add, commit, push

7.dev branches merged into the master branch
Note: Only when the dev branch into the master branch success, Joe Smith can get to num4

7.1 to switch to master branch
git checkout master

7.2 dev branches merged into the master branch
git merge dev

7.3 merge branch operations managers push to a remote repository

The completion of the merger in the local branch of default, Direct Push can be merged
git push

8. Zhang num4 merged synchronization manager
only when seating successful synchronization code, the branch to be successful merging
CD Desktop / zhangsan / info /
Git pull

Guess you like

Origin blog.csdn.net/weixin_44074810/article/details/91354094