git command and operation

Git basis

Git configuration before use

Configuring user name and email (useful when many people work together)

  1. Configuration Name $ git config --global user.name xxxx

  2. Configure Mailbox $ git config --global user.email [email protected]

  3. Check whether the configuration is successful $ git config --list

Note :

  1. Change Configuration -> Repeat the command

  2. Or directly modify the C:\Users\用户\.gitconfigpath is not uniform

Step submission

  1. git init Initialize git repository
  2. git status Viewing File Status
  3. git add File List trace file
  4. git commit -m 提交信息 Submit code to the repository
  5. git logView submit records
    git log --pretty=onelineto see simple commit record

Undoing Changes

  • Overwrite files in the working directory with the files in the staging area:git checkout

  • The documents in the work area to make changes complete withdrawal git checkout -- 文件名

    Undo divided into two cases:

    After 1.readme.txt automatically modified, not into the staging area, use the back and undo changes to the repository exactly the same state.

    2. Another is to put readme.txt already staging area, and then they made the changes, undo changes returned to the state after adding the staging area.

  • The file is deleted from the staging area:git rm --cached 文件名

  • The recovery git repository specified in the updating record came out, and covers the staging area and working directory:git reset --hard commitID

Git commit modify information in the author

  1. Use --amend modify author:

    git commit --amend --author=‘xxx <[email protected]>’

  2. Input git rebase --continueend modification

Back to the previous version

`` git reset --hard HEAD^ ``  回溯到上一个版本
`` git reset --hard HEAD^^ `` 回溯到上上个版本
`` git reset --hard HEAD~100 `` 回溯到100个版本之前

View the file contents

cat 文件名称

Advanced Git

Branch

A copy, to avoid affecting the development of the main line

Branch subdivision

  1. Main branch (master): first submitted a branch generated automatically update records to the git repository.
  2. Development branch (develop): developed as a branch, created based on the master branch.
  3. Feature branches (feature): Create a branch-based development as a function of the development of specific branches.

Branch command

  • git branch View branch
  • git branch 分支名称 Creating a branch
  • git checkout 分支名称 Switching branch
  • git checkout -b 分支名称 Create and switch to the branch (i.e. first two combined)
  • git merge 来源分支 Merge branch
  • git branch -d 分支名称 Deletion branch (branch can not be operated in a state) (- D forced to remove uppercase)

note:

After the development branch file you want to commit and then switch the main branch, branch or file will appear in the main branch inside.

Temporarily save changes

git can not commit the changes, just extract all the changes on the branch and store that allows developers to get a clean copy of the temporary turn to other work. Copy to "clipboard", you can "stick" to other branches.

Scenes:

  • Store temporary changes:git stash
  • Restore temporary changes:git stash pop

Github

Registration Github account

Man extravagant github

Multiplayer collaborative development process

  • A local repository is created in your computer
  • A creates a remote repository in GitHub
  • A local repository will be pushed to the remote repository git push
  • B clone a remote repository to local development git clone
  • B local warehouse development to push content to a remote repository git push
  • A remote repository latest local content got me git pull

Creating a warehouse

Pushed to the remote repository

  1. git push **远程仓库地址** 分支名称

  2. git push 远程仓库地址别名 分支名称

  3. git push -u 远程仓库地址别名 分支名称

    -u Remember PUSH address and branch, next only need to entergit push

  4. git remote add 远程仓库地址别名 远程仓库地址

  5. The first submission requires a user name and password, the computer will remember the password in the Credential Manager, and the second would not have had.

Pull warehouse

  • Clone remote repository to local:git pull 仓库地址

Cloning warehouse

  • Clone remote repository to local:git clone 仓库地址

Pull remote repository latest version

  • The latest version pulled a remote repository to local:git pull 远程仓库地址 分支名称

Resolve conflicts

When people develop the same project, if two people modify the same file in the same place

  1. git pull
  2. Manually resolve conflicts
  3. git push

Cross-team collaboration (github)

  1. forkTo their remote repository
  2. cloneTo locally modify
  3. pushTo a remote repository
  4. pull requestSent to the original author
  5. View the original author commitaudit
  6. Author merge pull request

SSH login avoid dense (recommended) (to be improved)

  1. Generate the key:ssh-keygen

    Key store directory:C:\User\用户\\.ssh

    Public Key Name:id_rsa.pub

    Private Key Name:id_rsa

  2. Add the keys Github

  3. Copy the SSH Address:

  4. Setting up ssh alias:$ git remote add origin_ssh SSH地址

  5. Remote Push:$ git push origin_ssh master

Git ignore list

  • Will not need to file name added to this file, it will ignore these files when executing commands git touch .gitignore

Rule action

/mtk 过滤整个文件夹
*.zip 过滤所有.zip文件
/mtk/xiaojian.py 过滤某个具体文件
!xiaojian.py 不过滤某个具体文件

Note : Before you push a certain file if you create .gitignore file, even if you write in .gitignore file filtering rules of the file, the rule will not work, git will still perform the file version management.

Configuration syntax

以斜杠“/”开头表示目录;
以星号“*”通配多个字符;
以问号“?”通配单个字符
以方括号“[]”包含单个字符的匹配列表;
以叹号“!”表示不忽略(跟踪)匹配到的文件或目录。

Note : git for .gitignore profile by rows from the top down rule matching

To add a description warehouse

Add in the warehouse root directory readme.mdfile to

Common graphical management tools (GUI)

  1. Github for Desktop: Github official produced

  2. Sourse tree: the old GUI

  3. TortoiseGit: namely turtles git

Guess you like

Origin www.cnblogs.com/newbase/p/11965446.html