git use and some errors

First, simple to use

  Git is the world's most advanced distributed version control system for automatically records each change file, but with all version control systems, can only track changes in text files, such as TXT files, web pages, all the code etc., and pictures, videos binaries, only recorded changes, but do not know what changed.

  With the largest difference between the centralized version control system: a centralized version control system must be networked to work, the speed is relatively slow; but Git has its own local warehouse, just when things look like synchronization, but also relatively safe, such as when the central server centralized version control system becomes a problem, it would be impossible to work.

1, install git

CentOS7  :sudo yum install git
Ubuntu Linux  :sudo apt-get install git

Windows: 
Git official website to download the installer, and then press the default installation. (Giant slow download speeds ...) to install a package, version: Git-2.19.0-64-bit.exe, you can first use: Portal

After installation is complete, find the "Git" in the Start menu -> "Git Bash":

$ git config --global user.name "github_name"
$ git config --global user.email "email_name"

2. Create Repository

Choose a suitable place, create a directory, then enter the directory, this directory can become a Git repository management

$ git init

You can find more than a .git directory of the current directory, the directory is to track and manage Git repository

Then add files to the repository:

$ git add filename

The submission of documents to the repository

The commit -m git $ " description " 

  -M is entered later explained this submission to facilitate the change record from the history list to find.

3, add a remote library

3.1 Creating SSH Key:

$ cd ~/.ssh
$ ls

Look at this directory has no id_rsa and id_rsa.pub these two files, if you already have, you can jump directly to the next step. If not, create SSH Key:

$ ssh-keygen -t rsa -C "email_name"

Landing GitHub, open the "Account settings", "SSH Keys" page, then, point "Add SSH Key", fill in any Title, paste the contents of id_rsa.pub file in the Key text box, click "Add Key". GitHub allows to add a plurality Key, easily pushed from different computers.

3.2 Local pushed to the remote repository

In the local warehouse operation command (the one who created directory):

$ Git remote add origin [email protected]: githubname / filename.git // link remote repository, create the main branch 
$ git push -u origin master // push the local repository of files to a remote warehouse

Since then, after each local commit as long as necessary, you can use the command git push origin master pushes the latest changes.

At this point, pushed to the remote repository from a local warehouse has been OK.

 

 Second, the commonly used commands

  Here are some commonly used commands:

$ Git status command to see the results 
$ git diff readme.txt see what specific changes to the 
$ git log command to display the most recent commit log from the furthest 
$ git reflog records every command

Version rollback

$ Git reset --hard HEAD ^   back to the previous version 
$ git the RESET --hard commit_id // commit_id is the version number, use $ git log command can see 
$ git Checkout - filename dropped modify the workspace 
$ git reset HEAD filename discard changes to the temporary area

Delete Files

RM git filename $ 
$ git the commit -m " the Remove filename " 
$ git Checkout - filename after accidental deletion, or modification to the work area is removed, can be "a key to restore"

Clone remote repository

$ git clone [email protected]:githubname/filename.git

 

Third, the problem arises:

1、Git: bash: cd: too many arguments 

The reason is because the path name or variable intermediate spaces, this time need to be enclosed in double quotes 

2、

  Before pushed to the remote repository add: $ git pull origin master 

$ Git pull origin master // to change the local repository of connection to a remote repository main branch 

$ git the Push -u Origin Master // the local repository of files pushed to the remote repository

3、

  Because my remote repository and local repository conflict caused in github repository page, click the create README.md file button to create the documentation, but did not pull to the local. This creates a problem in the versions conflict.

Solution:

 

3.1 Forced push method:

$ Git push -u origin master -f 
it would be modified remotely loss is generally not advisable, especially when many people work together to develop.

3.2.push before the first remote repository modify pull down

$ git pull Origin Master
$ -u git the Push Origin Master

3.3 if we are not. Merge remote and local changes, you can create a new branch:

$ git Branch [name]
and then the Push
$ git push -u origin [name]

 

 

Reference Address: https://www.cnblogs.com/code-changeworld/p/4779145.html

Use more about git can refer to: Liao Xuefeng teacher Git tutorial

Guess you like

Origin www.cnblogs.com/BackingStar/p/11111197.html