Get the foundation

This blog from teacher Dary
basic use of the Git (a)
tool git
directory
Git uses
the Git hosting platform for
Git workflow
introduce the concept of
workflow
using Git step
version management
branch management
common branch naming
conflict resolution
Appendix 1: Git common commands
Appendix 2: Some precautions when using Git in
Appendix 3: Notes information when submitting Git

Git uses
managed code to a remote, distributed hosting, to avoid irreparable damage to the machine disk situation.
Version control, you can publish and implement multiple versions of shuttling back and forth between the various versions (implementation principle: file snapshots, each version will have a snapshot of the file quickly and easily than direct backup files therefore, Git repository is also known as the repository. ).
Teamwork, a strong branch functions make it easy for team collaboration
Git code hosting platform
github: https://github.com

github is the world's largest open source social programming and code hosting site, also known as the world's largest gay dating (gayhub)

coding: https://dev.tencent.com

Reached a strategic cooperation with Tencent cloud, cloud-based technology, software development platform, set project management, code hosting, running space, quality control as a whole.

gitee: https://gitee.com

Cloud code (gitee.com) is OSCHINA.NET launch code hosting platform that supports Git and SVN, provides free private repository hosting.

Concepts
workspace: local workspace
Index: staging area
repository: local repository
remote: remote repository
workflow
to achieve code hosting, you need local init a local warehouse, added to the staging area through the add command, then commit to submit local warehouse (each will have to submit a new version), the final push to push through remote

Git step using
this to gitee an example explaining to do, or the reader can choose github Coding, using the same procedure used in step [] Brackets enclosed part needs to your local corresponding, unwanted retention brackets .

The first time to install git to perform steps 1-4. Otherwise, start from step 5

Install git tools after installation is complete as long as the right mouse button menu appears git bash here namely the installation was successful.

windows system Download link

MAC Download Link

Registration gitee account (account number or other platforms), modify personal space address, binding mailbox.

Global configuration user name and mailbox

git config --global user.name [your cloud account code]

git config --global user.email [cloud your code verification mail]

Configuration of Key: generating a public and private keys for secure validation codes upload

In git bash in the execution command ssh-keygen way to enter, you can generate a key pair, the default key pair is stored in the (/ c / Users / [host username] /. Ssh /). There are two files in this directory, .pub is public, the other is a private key, these two files do not move! ! !

To line (gitee or other platforms) Open the Settings -> Security Settings -> ssh public key, the local public key file Select Copy in, enter the login password, you configure a success.

When you first create a project execution steps 5-7, otherwise start at step 8

Create a local warehouse

Creating a local project folder, the project code in this folder, execute git init to initialize a local git repository, this time there will be more of a project .git directory (this directory is hidden by default, this is used to store file snapshot place), this catalog do not move! ! !

Creating an online warehouse

Log gitee, the new warehouse, enter a project name, select a private or open source (before joining the private partner will only be able to see yourself, open means open source), following Do not tick a box (not initialized files from a local warehouse, warehouse line does not require any file), and finally click create ok.

The local warehouses and online warehouse associate: git remote add origin [SSH address line warehouse]

If an error in the implementation of this sentence: fatal: remote origin already exists.

Then the first execution git remote rm origin

And then re-execute the git remote add origin [SSH address line warehouse]

Code is added to the staging area git add -A (may git add [filename] is added to a document to separate)

Code is submitted to the local repository git commit -m '[this submission instructions made by the more detailed the better]'

Code push remote git push origin master

Version management
to have been placed in the temporary area of content back to the work area

Index.txt file back to the staging area

git reset HEAD – index.txt

ceshi file back to the staging area folder

git reset HEAD – ceshi/

All the files back to the staging area

git reset HEAD -.
historical version rollback

1
2

Version history

log git
git version information
git version information

commit string behind here is the version number, we can use git reset --hard historical version number fallback

Fall back to the first version submitted

git reset --hard ce0c17f7a703c6847552c7aaab6becea6f0197f2

Fall back to the second version submitted

git reset --hard abb2c4f12566440e04bc166c3285f855a37a3bb2
branch management
git branch that we own our entire folder into a a separate area, such as in the development of my login function, can be placed under the login branch development; development of a list of functions when can be placed under the list branch development, we interfere with each other, each function is a separate feature branches, so that developers will be much better.

git at initialization, automatically generates a branch, called the master, is a major branch of meaning, we can open up a lot of their own based on master independent branch

It has opened a branch using git branch name branch instruction

1
2

Login to open up a branch

$ Git branch login
to view the situation at the current branch

1
2

View current branch circumstances

$ Git branch
looking at branches situation
View bifurcation

We can already see, currently has two branches, the one master, one login. * In front of a number, and it has highlighted to indicate your branch is currently located.

We want to develop mobile sign-on capabilities to branch to complete the login, then you can switch to another branch, use git checkout branch name

1
2

Branch switch to login

$ Git checkout login
and then we develop the login function on the entire login branches. After the development is completed, we will submit in the current branch, then branch after submission we switch back to master the most original master was found on top of the state, while the code we write new login feature on the login branches. We follow the branch all the functions after the completion of the development, all of the code needed to be incorporated into the master main branch.

git branch merge, only the contents of the other branches merged into their own branch

Git merge instruction using

1
2
3
4
5

Switch to the master branch

$ git checkout master

The login of content into their own branch

$ Git merge login
this time, we are just on the login develop things have come on the master main branch, if there are multiple branches, then all eventually merge to time on the master branch, our main branch all pages will have a complete site, are separate pages and functions on each branch. This time we opened a branch there is no good anymore, you can delete the branch

First switch to another branch

Use git branch -d command to delete the branch name

1
2
3
4
5

First switch to another branch

$ git checkout master

Delete login branch

$ Git branch -d login
common branch name
when using a branch of our branch should try to regulate some of naming, we have some default branch name we all have a special meaning, such as we wrote before login is not standardized branch the name of the branch.

Common name of the branch

master: main branch, always stores only one version can be stable operation, can no longer be the branch directly to the development of
develop (dev): The main development branch, primarily intended for code function development used by the merger, record full version of one of the
test version includes and stable release
not to this development branch
feature-xxx (feat-xxx) : functional development branch, from the branch dev created mainly used for the development of a single function, with their function name on the line, for example feat-login / feat -list, after completion of the development merged into the dev branch
feat-xxx-fix: bug appears after a branch to open a branch in the current fix branch, such as log function bug, can be based on feat-login to open a new branch feat -login-fix, solve the bug after completion, merged into the current branch function, if it is found that bug can be opened directly on the develop branch merged into the dev branch function after the repair is completed after the branch has been merged
hotfix-xxx: for emergency bug repair, directly on the master branch opened, after the repair is completed merged back into master
conflict resolution
git conflict In our upload process, the local version and the remote version of the inconsistency caused, this time as long as the first use git pull pull back and let local and remote consistent, and then re-upload just fine, but git pull relatively insecure , as it will automatically merge and local content, we can choose to use git fetch

1
2
3
4
5
6
7
8

Use remote fetch obtain the latest information and opened a temporary branch

$ git fetch origin master:tmp

The contents of the current temporary branch and branch comparison

$ git diff tmp

Then select Merge branch content

$ Git merge tmp
Appendix 1: Git common command
git init initialization warehouse
git config configuration user information
git remote add origin [online warehouse address] associated with new remote repository
git remote rm origin delete the associated remote repository
git add to add to the staging District
git '[Remarks the information submitted]' code delivery commit -m (each commit will have a new version number)
git the push Origin [branch] pushed to the remote repository
git status to view the current status of the warehouse
git log View log (each commit here to be able to view and commit random string behind is the version number), according to the letter q to exit the log
git the RESET --hard [to roll back the version number] a version prior to fall back
git clone [online Storage address] the cloned line of code to the local repository
git pull origin [branch] to pull a new branch of the code line on the basis of the existing warehouse, incorporated directly after pulling
git fetch origin [branch name] on the basis of the existing warehouse to pull a branch of the latest line of code, and then pulled up to the user whether to merge
git branch looking at branches
git bra nch newBranch branch based on current branch to create newBranch
delete myBranch branch git branch -d myBranch
git diff tmp tmp view the current branch and the branch of the difference between
git merge tmp The tmp branch into the current branch
Appendix 2: Some notes Git time
a local repository corresponds to a remote repository
remote code and native code to maintain the unity
.git files can not be nested (warehouse can not nest)
Appendix 3: Git when remark information submitted
for explaining commit categories, only allow use of the identification 7

feat: new features (the Feature)
FIX: Patch bug
docs: Documentation (Documentation)
style: format (does not affect the operation of the code changes)
Refactor: the reconstruction (ie, not new features, bug fixes nor code changes)
the Test: increase test
chore: building the change process or aids

Article Title: Basic Git use of (a)

Published an original article · won praise 0 · Views 17

Guess you like

Origin blog.csdn.net/weixin_42301175/article/details/104468087