Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

[git] command line operation

Nemo& 2021-01-14 17:04:53 阅读数:7 评论数:0 点赞数:0 收藏数:0

Git Command line operations

1 Local library initialization

git init: Initialize local warehouse

effect

Be careful :.git The directory contains subdirectories and files related to the local library , Don't delete , And don't modify it .

2 Set signature

form :

 user name :tom
Email Address :goodMorning@atguigu.com

effect : Distinguish the identities of different developers

Differentiation and analysis : Here you set up the signature and login to the remote library ( Code hosting Center ) Account number 、 The password doesn't matter .

command

  • Project level / Warehouse level : Valid only in the current local library range
    • git config user.nametom_pro
    • git config user.emailgoodMorning_pro@atguigu.com
    • Information storage location :./.git/config file
  • System user level : The range of users who log in to the current operating system
    • git config --global user.nametom_glb
    • git config --global goodMorning_pro@atguigu.com
    • Information storage location :~/.gitconfig file (~ Represents the root directory )
  • Level priority
    • Nearby principle : Project level takes precedence over system user level , Both sometimes use project level signatures
    • If only the system user level signature , It is subject to the system user level signature
    • Neither of them is not allowed

3 Basic operation

3. 1 Status view

git status: Check out the workspace 、 Staging area status

3. 2 add to

git add [filename]: Put... In the workspace “ newly build / modify ” Add to the staging area

  • filename: For the file name to be added ,* All files representing the current directory .

3. 3 Submit

git commit -m "commit message" [filename]: Commit the contents of the staging area to the local library

3. 4 View history

git log: View history , Display full history information

Multi screen display control mode :

  • Space : Page down
  • b: Page up
  • q: sign out

The history shown in the above method may not be very good : We can use the following methods to simplify the display of history :

git log --pretty=oneline: We can use this command to put history on one line

git log --oneline: The display of hash value is shortened , Just show the back 7 position

The above methods can only show the past and the present


The following command shows the past 、 Present and future

git reflog: This way you can see all of our history , Including before going back 、 After fallback 、 In the past 、 Now? 、 future .

HEAD@{ How many steps does it take to move to the current version }

3. 5 Forward and backward

The essence : Use git reflog To show all the history

You can use the following methods to move HEAD The pointer

Operation based on index value [ recommend ]

  • git reset --hard [ Local index value ]
  • git reset --hard a6ace91

Use ^ Symbol : You can only go back

  • git reset --hardHEAD^: One ^ Take a step back ,n One means back n Step

Use ~ Symbol : You can only go back

  • git reset --hardHEAD~n: Back off n Step

3. 6 reset The three parameters of the command are compared

The original local library 、 Temporary storage area 、 The three versions of the workspace are the same :

--soft Parameters

  • Just move in the local library HEAD The pointer

    You can see here , Our local library version is a step back , And nothing else has changed

--mixed Parameters

  • Move in the local library HEAD The pointer
  • Reset staging area ( Reset , namely Back version )

--hard Parameters ( This is the most used )

  • Move in the local library HEAD The pointer
  • Reset staging area
  • Reset workspace

3. 7 Delete files and retrieve

Premise : Before deleting , The state of the file when it exists is submitted to the local library .

operation :git reset --hard [ Pointer position ]

  • The delete operation has been submitted to the local library : The pointer position points to history
  • The delete operation has not been committed to the local library : The pointer position uses HEAD

3. 8 Compare file differences

git diff [ file name ]: Compare the files in the workspace with the staging area

git diff [ Historical version in local library ] [ file name ]: Compare the files in the workspace with the local library history

git diff: Compare multiple files without a filename

4 Branch management

4. 1 What is a branch ?

During version control , Use multiple lines to advance multiple tasks at the same time .

4. 2 The benefits of branching ?

  • At the same time, multiple functions are developed in parallel , Improve development efficiency
  • Each branch in the development process , If a branch fails to develop , No impact on other branches . The failed branch deletion can be restarted .

4. 3 Branch operation

git branch [ Branch name ]: Create a branch

git branch -v: View branches

git checkout [ Branch name ]: Switch branches

Merging branches

  • First step : Switch to the branch that accepts the modification ( Be merged , Add new content ) On
    git checkout [ The name of the merged Branch ]
  • The second step : perform merge command
    git merge [ There are new content branch names ]

Resolve conflicts

  • The manifestation of conflict

  • The resolution of the conflict
    • First step : Edit the file , Delete special symbols
    • The second step : Modify the document to a satisfactory level , Save and exit
    • The third step :git add [ file name ]
    • Step four :git commit -m " Log information "

      Be careful : here commit You must not bring a specific file name

Common operation steps of command line

Situation 1 : Create your own projects

1. Create a remote library


2. Create remote library address alias

git remote -v View all current remote address aliases
git remote add [ Alias ] [ Remote address ]

3. push

git push [ Alias ] [ Branch name ]

Push requires an account number and password :

Situation two : Clone other people's projects

1. Clone remote warehouse ( From scratch )

git clone [ Remote address ]

effect

  • Download the remote library to local completely
  • establish origin Remote address alias
  • Initialize local library

Situation three : Update existing projects

1. Pull ( From old to new )

  • pull=fetch+merge
  • git fetch [ Remote library address alias ] [ Remote branch name ]
  • git merge [ Remote library address alias / Remote branch name ]
  • git pull [ Remote library address alias ] [ Remote branch name ]
Copyright statement
In this paper,the author:[Nemo&],Reprint please bring the original link, thank you