GitHub command collection and operation tutorial

1. Briefly describe the difference between SVN and GIT
SVN: Centralized GIT: Distributed
1.SVN:
(1) Features: All historical versions are established on the central server, and the local client is just a development environment. It needs to be pushed to the server to generate a historical version, it needs to be rolled back to a certain version, and it also needs to be pulled from the central server
(2) Disadvantage: it must be connected to the central server (must be connected to the Internet)

(3) Work diagram
insert image description here
2. GIT
(1) Concept: The so-called distributed means that each developer’s local client is a complete warehouse, which can record historical version information
(2) Features: no need to connect to the Internet, We can also generate version records, and quickly roll back to a certain version
(3) Working diagram
insert image description here
3. The difference between SVN and GIT
(1) Centralized version information can only be recorded on the central server, and can only be pulled from the central server Or roll back a certain version of information. Such a premise must ensure that the client is connected to the central server and must be connected to the Internet . Distributed it treats each client as a brand new separate warehouse. Click to complete the creation and rollback of the version. You don’t need a central server . Of course, teamwork requires a central server. Collect everyone’s information on the central server. Just pull the latest version of the central server to the local. You can directly view or roll back the version, he does not need to be connected to the Internet
(2) Git implements file transfer according to source data (file stream), while svn transfers files according to file, so GIT is faster than svn

2. Commonly used instructions
Note: GIT is developed by the linux team, so most of the commands in git are linux commands
1. Install GitHub first
(1) Download: https://git-scm.com/downloads
(2) When installing The default is the next step
(3) to complete the installation. There are two ways to check whether it is successful:
you can enter git --versionthe check version information
or
the desktop has a key to see if it is there (as shown in the red box in the figure), and the installation is successful if it is. insert image description here
2. Based on the command How to configure the name and eamil to complete
the basic commands of GIT management? //set name //email

$git config --gloabal user,name 'xxx'
$git config --gloabal user.eamil 'xxx'

ls -l或者ls -a: View file directory

-l: view the current directory structure -a: you can see all: including hidden

cd xxx[路径地址]: Enter the specified file (the address entered can be entered in the corresponding operation command window)

 cd / :表示根目录    cd ./ :切换到当前目录   cd ../ :切换到上级目录

clear:clear screen
mkdir:create folder

mkdir text   //创建text文件

touch: Create an empty file and insert it with vi

  touch 1.js  创建了1.js文件

vi: Insert or manage some content into the file, and then press i=> to enter the insert mode.
ESC+ :WQ: Exit the insert mode of the content, and save the edited content just ESC+ :q!now: Forced exit, the current content will not be saved
(generally vi, i, ESC (the esc key on the keyboard), :wq or :q are all used in succession, Because vi is to insert some content, i is the insert mode, you can enter the content in the insert mode, and it will save and exit after the insertion is completed)

 举例:如vi 1.js 回车 再按i 显示--插入模式-- 然后写点东西  let a=12; let b=13;conslog(a); 再然后保存:按 i 后 再按esc(退出插入模式)再输入:wq(保存并退出)

echo: Enter (insert) content into the specified file, and also create a file by the way
(feature: it will overwrite repeated input and only save the latest piece of information)

语法:echo xxx > xxx.txt 或者 echo xxx>>xxx.txt

Such as: echo hahaha>2.js //Input hahaha into 2.js
cat: view the content in the file

想查看1.js的内容  :输入 cat 1.js 即可

rm:Delete files or folders
-r 递归删除 -f 强制删除, once deleted cannot be restored
rm *: delete all
rm *.js: delete all js
rm node_module -rf: //Delete node_module, because there are many files in it, -r can also be forced to delete, just -rf
cp: copy
advanced command
$git init : create GIT warehouse
$git add -A 或者git add .: Submit all the modified content in the current workspace to the temporary storage area (you can specify the specific submitted file $ git add xxx.js):
$ git commit -m'写版本备注'Submit the content in the temporary storage area to the historical area to generate a historical version (we need to write remarks , to declare the characteristics of the current version)
$ git statusCheck which area the currently modified file is in Check the version, compare the information (as follows:)
Red: Work area
Green: Temporary storage area
invisible: It has been submitted to the history area, and the three areas are consistent

$git rm --cached xxx.xx : Delete one of them
$ git rm --cached . -r: revoke all submissions in the temporary storage area
(if during the deletion process, it is found that the files deleted from the temporary storage area have been modified in the work area, only by adding -f can the content be forced from the temporary storage area Deleted)
$git checkout xxx.xx: Submit a copy to the temporary storage area, and change the content of the work area, but the changed things are not good. I want to revoke the content submitted last time in the temporary storage area and return it to the work area (overwrite the newly written content in the work area)
Features: There is no news in the temporary storage area, but the latest modified information in the work area is overwritten, so that the work area and the temporary storage area are consistent:
$git diff <file>view the file DIFF
(compare the difference between the current file and the temporary storage area)

 git diff 1.js //比较1.js的不同

git checkout .: Code rollback (roll back the content of the temporary storage area to the work area (once rolled back, the content of the work area cannot be restored)) :
git reset HEAD .Roll back the content of the current temporary storage area to create a new temporary storage area, the purpose is to Roll back the contents of the temporary storage area to the work area
git reset --hard 版本号: roll back to a certain version in the middle of the history area (forcibly change both the temporary storage area and the work area to the rolled back version)
history > xxx.txt: output the historical operation steps

git logView submission records
git reflogView all historical records (including after rollback in the historical area)
git commitSubmit to the historical area
git commit -m'xxx'Submit to the historical area
3. GitHub's basic workflow and commands
We all know that every GIT warehouse has three areas:
work area: write code
Temporary storage area: Temporary storage of each modified code. But no historical version has been generated History
area: the place where all historical versions are stored
So what is the workflow like, the process from scratch is as follows:
Basic process:
1) First create a central warehouse :
open the official website of github, after logging in, First create repository (create a new warehouse)
insert image description here
to complete the creation. If it is a newly created library, you can use the command to create a non-empty warehouse first (the purpose is to ensure that the central warehouse has a master branch)

echo "# mytest" >> README.md  //添加个记录
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/MNLNG/mytest.git
git push -u origin master 

If you already have a central warehouse, you can just clone it directly without the above operations.
2) Creating a client local warehouse is the code for cloning the central warehouse :
$git clone "远程仓库地址" "本地仓库文件夹名字: (If you don’t write, the default is the warehouse name)"

如 $ git clone https://github.com/xxx/2020xxx.git TEST 

The following is a complete process of a client from cloning code to adding files, submitting, modifying, and uploading to the central warehouse
(1). First clone two clients A and B

git clone https://github.com/zhufengpeixun/201802TEST.git TESTA
git clone https://github.com/zhufengpeixun/201802TEST.git TESTB

(2) Create file and content 1.txt in TESTB and create file and content 2.txt in TESTB
(3) cd to the corresponding client directory

cd TESTA 

(4) Submit the files created by the client

Add files before submitting

git add .

then submit

git commit -m'我是A客户端 创建1.txt'

You can check the version

$git log

(5) Then push, pull before pushing

git pull origin master 

Then submit to the remote

 git push origin master 

(6) Respectively synchronize information with the central server

git pull origin master

Well, it's done, isn't it very simple, haha!

4. Files that can be ignored when submitting
such as ##dependencies

 /node_modules

##testing

 /coverage

##production

/build

##misc

.DS_Store 
.env.local .env.development
.env.test .local  
.local  .env.production .local 
npm-debug.log*

yran-debug.log*

yran-error.log* 

.idea

5. Team collaboration and branch management
Generally in the team, small projects may adopt the non-branch management mode, which is relatively simple. In fact, the management of one branch is usually enough, but there are also large companies that use multiple branches to manage, so that’s the case Do some analysis
The branch refers to the branch in the historical area: creating a branch is to create a different line to manage the historical version
(1) No branch management mode
1. Daily work mode:
first pullcome down first, if there is a conflict, deal with it first, and then Put the file add ,commit, and then pull 和push(I ignore the abbreviation of git ... for the command here, just add it when executing it)
2. Resolve conflicts
- conflicts not on the same line: just agree in the conflict command prompted ESC :wq(press the ENTER key), If the local and central ones want to keep the central one, then esc: q to force exit
- the same line conflict:
keep what you want: the attempt to merge fails, we need to manually merge the code and then resubmit it. If you
don’t want to save it, then esc :q Forced to exit the code that keeps the central warehouse
(2) Separate branch mode
1. Normal development and submission, but all operations are on your own branch
2. Merge the contents of your local branch into your local master On the branch
$git stash//temporary file (the branch is changed by the branch, you can't switch the branch directly, you need to temporarily store the modified content),
$git checkout master//switch to the master branch
$git stash pop//restore the temporarily stored content
$git merge dev//merge the dev branch into the master branch (If there is a conflict, modify it according to the previous conflict rules)
Note: These operations are when the workspace and temporary storage area have not been submitted to the historical version, we implement branch switching to prevent information loss, we first use git stash to store it temporarily, and then git stash pop when switching to the master Restore the saved data, and then merge the dev branch into the master branch. If the historical version has been submitted, there is no need for temporary storage, and it can be merged directly

Merge : If you are currently writing git merge dev on the master branch //Represents dev being merged into the master branch
If you are currently on the dev branch, write git merge dev1 //Represents dev1 being merged into the dev branch

2. Steps from creating a branch to merging a branch
Before creating a branch, look at the currently existing branch
$git branchto view the currently existing branch

  • master "*" represents which branch it is currently on.
    insert image description here
    The above figure represents that there are two branches
    (1) create a branch first
    git branch devand create a branch called dev
    (feature: after creating a new branch, the content in the local master branch will be synchronized to the dev branch Above)
    git checkout devSwitch to the dev branch
    git checkout -b devCreate and switch to this branch
    (2) After completing the branch, push the commit to the central warehouse
    git add . -"git commit -m'note' -"git pull origin master -"git push origin master
    ( 3) Then switch branches, temporarily store (stash), merge (merge)
    first switch to the master branch and then merge
    $git checkout master//switch to the master branch
    $git stash pop//restore the temporarily stored content//
    $git merge devmerge the dev branch into the master branch
    as Some conflict
    insert image description here
    resolution ideas: first press esc:wq and then push again

Guess you like

Origin blog.csdn.net/weixin_41262185/article/details/105471897