Introduction to Git's common commands

Introduction to Git's common commands

Introduction

Git is a distributed version management system, a version control tool for Linux kernel development. It uses a distributed version library, without server-side software support to make the release and exchange of source code extremely convenient. Git is very fast, which is naturally important for large projects such as the Linux kernel. The best thing about Git is its merge tracing capability.

.

.

Steps to host a local project to GitHub

  1. git init: Initialize the warehouse

  2. Create a remote repository on GitHub

  3. Copy the HTTPS address of the remote warehouse

  4. git add README.md: documentation for creating the project (put it in the cache)

  5. git commit -m "first commit+log content": submit all files

  6. Create a remote warehouse alias locally (git remote add origin + warehouse address)

  7. git push -u origin master: synchronize the files in the local warehouse to the remote warehouse

  8. Download the project from GitHub to the local (git clone + project address)

.

.

Github submitted updated code:

  1. git status: View the code of which files have been changed

  2. git add the changed files you want to commit or git add. All files;

  3. git commit -m'submit information' submit the files in the temporary storage area of ​​the local warehouse to the local warehouse

  4. git push -u origin master: synchronize the files in the local warehouse to the remote warehouse

.

.

Invite others to join your team:

  1. Click on the Settings of the repository on GitHub

  2. Click Collaborators

  3. Then enter the username or email address of the person you want to invite and press OK

  4. Copy the link address -> open the link and confirm to join the team

Linux commands

.

  • ll: View all files in the current directory (not including hidden)

  • ll -lA: View all files in the current directory (including hidden)

  • cd + path: switch directory ( cd …: return to the parent directory)

  • cat + file path: view the contents of the file

  • pwd: view the current directory

Note:

Press Tab: Incomplete commands

.

.

Set signature: (item level)

  • git config user.name + user name: set user name (project level)

  • git config user.email + email account: set up email account (project level)

Set signature: (system level)

  • git config --global user.name + username: set the username

  • git config --global user.email + email account: set up email account

.

.

Git branch command

  • git branch -v: view the current branch

  • git branch [branch name]_fix: create a new branch

  • git checkout + branch name: switch branch

  • git branch -d + branch name: delete a branch (switch to another branch to delete, not suicide)

  • Merging branches (no conflict (usually back to the main branch)):

git merge + branch name of other branch:

  • Merging branches (with conflicts (usually back to the main branch)):

(1) git merge + branch name of other branch

(2) Exchange conflict resolution

(3) Edit the conflicting file with vim (1. Delete the automatically generated content 2. Modify the content)

(4) Submit the file again -git commit -m "log content" (do not add the file name)

.

.

Commonly used Git commands

.

  • git init: Initialize the warehouse

  • git status: view the current status (red is not added to the buffer area, green means it has been added to the buffer area)

  • git add + the changed file you want to submit or git add. All files: submit files to the cache

  • git commit + file name: After submitting the file, a log file edited by the vim editor will be opened and the log will be written in it (you can write in Chinese, do not specify a file = submit all files)

  • git rm --cached + file name: remove a file (cache area)

  • git log: view the submitted records (git log --pretty=onelin: display records on one line (or git log --onelin)

  • git reflog: display the number of steps back)

  • git reset --hard + hash value (local index): back to a certain version (back and forward are the same)

  • rm + file name: delete the file (if you want to roll back, you must add it to the cache first. If you want to retrieve it, use "git reset --hard + hash value (local index)")

  • git diff + file name: compare the differences of files (git diff + local index + file name: the difference between the historical version of the file and the current file)

  • git remote -v: View the aliases of all current remote addresses

  • git remote add + alias + remote warehouse address: create an alias for the remote warehouse address

  • git push -u + address alias + branch name: push (synchronize the files in the local warehouse to the remote warehouse) (if it is a warehouse created by someone else, it can only be pushed after joining the team)

  • git clone +remote warehouse address: clone someone's warehouse (also with: branch name and address alias, and help you initialize the local warehouse)

  • git fetch + remote library address alias + remote branch name: pull remote warehouse

  • git checking +remote library address alias/remote branch name: switch to the pulled warehouse (you can review the code)

  • git merge +remote library address alias/remote branch name: merge and pull remote repositories

  • git pull + remote library address alias + remote branch name = fetch (pull) + merge (merge)

Note: If there is a conflict, it is resolved like a merge branch

.

.

Usage of vim editor (default is command mode)

.

  • vim + file name. Format: create file

  • I key: switch input mode

  • Esc key: After returning to the command mode, press ":" and then enter the command

  • wq: save and exit (wq: force save and exit)

  • set nu: display line number (to be in: (command mode))

  • Spacebar: page down

  • b: page up

  • q: Exit paging

Guess you like

Origin blog.csdn.net/weixin_42324979/article/details/113115008