This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together

Use the git

What is a git

Git is an open source distributed version control system designed to handle any project, small or large, with agility and efficiency. Git is an open source version control software developed by Linus Torvalds to help manage Linux kernel development. Git is different from the common version control tools such as CVS and Subversion. It adopts the way of distributed version library without the support of server-side software.

1. Download the git

git-scm.com/

2. Configure user information

Configure the user name and email address of the individual: Git config –global user.name “root” git config –global user.email [email protected] The changed profile is the one in your user’s home directory and will be used by default for all future projects. To use a different name or email for a particular project, simply remove the –global option and reconfigure it. The new Settings are stored in the.git/config file of the current project. Set Git’s default text editor to Vi or Vim. If you have other preferences, such as Emacs git config –global core.editor XXX

Viewing Configuration Information

 git config --list
Copy the code

Sometimes you see duplicate variable names, which means they come from different configuration files (such as /etc/gitconfig and ~/.gitconfig), but ultimately Git actually uses the last one. These configurations can also be seen in ~/. Gitconfig or /etc/gitconfig

 cat ~/.gitconfig
 cat  /etc/gitconfig
Copy the code

Edit the configuration

Edit git configuration files:

 git config -e    # target the current repository
 git config -e --global   For all warehouses on the system
Copy the code

3. Common commands

Creating a Git repository

git init
Copy the code

Add the workspace to the staging area

git add .
Copy the code

Submit the staging area

git commit -m "Submission Name (English)"
Copy the code

View the current workspace status

git status
Copy the code

See the log

git log
Copy the code

Project copy

git cloneaddressCopy the code

4. Roll back the version

— Hard, staging area, workspace (modified code will disappear) — Mixed staging area, staging area –soft Staging area

Git reset Version number /~Copy the code

Eg: Roll back n versions

git reset ~n
Copy the code

Mixed is recommended.

git --mixed reset ~
Copy the code

Switch version

git checkout XXX
Copy the code

Overwrite the last submission information

git commit --amend
Copy the code

5. Remote operation

6. Ignore files

Create gitignore.

 git touch .gitignore.txt
Copy the code

Append all files with the temp suffix to the ignore file

 echo *.temp >> .gitignore
Copy the code

Resubmit

7. Create a branch

Basic knowledge: master branch call master suggest new branch: feature_ new development (beginning capital hump) the name of the function of every time to develop a new feature to create a new branch After development to merge at once The development of columns such as login: git branch feature_Login

create

Git branchCopy the code

Switch branch

Git Checkout branch nameCopy the code

Merging branches

Git merge branch nameCopy the code

Delete the branch

-d:delete

Git branch -d Specifies the branch nameCopy the code

Branch conflict

Multiple people change the same file when generated, as long as found immediately put forward!

8. Commit the merge

Commit merge can be used when there are many commits in a day or on a function but only one commit is required to complete

git rebase -i head~~
Copy the code

Change the following pick to sAnd then you’ll see thisThen modify the submission informationThen usegit logTake a look and you’ll find the commits

9. The idea of integration of git

You can also configure a pluginHere is my configuration

use

At the bottom right hand corner