Git uses the common commands of GIT series from getting started to collecting dust in the earth

Posted by phorman on Thu, 03 Feb 2022 06:34:47 +0100

Git uses the ash eating series from entry to earth collection

πŸ“’πŸ“’πŸ“’πŸ“£πŸ“£πŸ“£

Hello! Hello, I'm [Xiao Zhang], a highly motivated blogger! 😜😜😜

✨ Writing style of [Xiao Zhang]: I like to explain every knowledge point in [easy to understand] style, rather than using [tall and tall] official statement.

✨ [Xiao Zhang] the blog is mainly about the notes and experience in the process of learning

✨ Welcome to [Xiao Zhang] πŸ’žπŸ’žπŸ’ž

❀️❀️❀️ Thank you, big and small! ❀️❀️❀️

1, Foreword

Talk about Xiao Zhang's feelings: I haven't been in contact with Git, so I watched a lot of videos. For getting started, it's really enough to know Git clone, git add, git commit, Git push and Git merge. But I'm curious about the principle behind it. Why use git add to the temporary storage area instead of git commit directly? Why should many instructions be executed in a certain order? So when I first learned this series, Xiaobai's point of view is from installation to working principle (some are my own opinions. If I feel wrong, please correct), and then to practical application! In addition, it is recommended to watch the third reference video and then the second reference video. The explanation of the working principle and practical application are really good!

2, Common commands

Put the order here first. You don't need to understand it. I'll practice later. If I can't understand it, come back and check it.

2.1 linux commands

Always use it more! These can be used directly in Git Bush Here. CMD cannot be used.

  1. cd change directory
  2. cd . . Go back to the previous directory and directly CD into the default directory
  3. Start < filename > open file
  4. Cat < file name > displays the contents of the file in the command window
  5. VIM < file name > edit the file in the command window and press "Esc" to enter ": wq" to save the file: e! "Discard changes
  6. pwd displays the current directory path
  7. ls(ll) lists all the files in the current directory, but LL (two ll) lists the contents in more detail
  8. Touch creates a new file, such as touch index JS will create a new index in the current directory JS file
  9. rm deletes a file, rm index JS will put index JS file deleted.
  10. mkdir to create a new directory is to create a new folder
  11. rm -r delete a folder, rm -r src delete src directory rm -rf / do not try in Linux! Delete all files in the computer!
  12. mv move file, mv index html src,index.html is the file we want to move, and Src is the target folder. Of course, in this way, we must ensure that the file and the target folder are in the same directory
  13. reset reinitializes the terminal / clear the screen.
  14. clear screen
  15. History view command history
  16. Help help
  17. Exit exit
  18. '#' indicates a comment

2.2 common git commands

Combine picture memory with basic commands!

Generally, to submit a record, you only need to execute git add in turn, git commit,git push. All operations are valid for the current branch. Add origin to specify the branch.

# Add all files to staging area
git add .      

# Adds the specified file to the staging area
git add <filename>

# Submit the contents of the staging area to the local warehouse
git commit -m 		#"Message content" -m represents information submitted

#  push the current branch to the remote (the branch exists remotely)
git push

# Push the xxx branch to the remote, because there is no new xxx branch on the remote, so - u should be added. You need to add - u when submitting a new branch to the remote for the first time
git push origin xxx
git push -u origin xxx				# Same effect
git push --set-stream origin xxx 	# Same effect

# Pull the latest content of the remote host locally without merging
git fetch

# Pull the latest content of the specified branch of the remote host to the local without merging
git fetch <The remote host name defaults to origin> <Branch name>

#  Pull the latest content of the remote host locally and merge it directly with the current local branch (only the current branch) is equal to fetch+merge
git pull
git pull origin <branchName> # Specify branch

Other common commands

# clone
git clone

#View all file status
git status

#View specified file status
git status <filename>

# List all local branches
git branch

# List all remote branches
git branch -r

# Create a new branch, but still stay in the current branch
git branch <branch-name>

# Create a new branch and switch to it
git checkout -b <branch-name>

# Switch to another branch / record
git checkout <branch-name>

# Merge the specified branch to the current branch
git merge <branch-name>

# Merge remote branch to current branch
git merge origin <Remote branch>

# Delete branch
git branch -d <branch-name>

# Delete remote branch
git push origin --delete <branch-name>
git branch -dr <remote/branch>

# Merge by branch to specified branch base
git rebase 

# Variable base 	 Integrate into one
git rebase -i <Hash value>
git rebase HEAD~number 	#Merge from the current record to the first x records

# Move files added to the staging area out
git reset <filename>

# Recover deleted files
git reset <Hash value>--hard

# Saves all uncommitted changes (workspace and staging) to the stack
git stash

# "Pick" submission
git cherry pick

git log

# View submission records
git log

# View submission records expand to show the content differences of each submission
git log -p

# View the difference between the remote submission record and the local one (git fetch must be pulled first)
git log -p FETCH_HEAD

# Graphical record
git log --graph

# Simplified graphical recording
git log --graph --pretty=format:"%h %s"
git log --graph --oneline

# Check if there are in dev but not in master
git log dev ^master 

# Check what more content is submitted in dev than in master
git log master..dev

# I don't know who submitted more and who submitted less. I just want to know what's different
git log dev...master

# View all records, including deleted files
git reflog

git diff is used to compare the differences between files

# When the work area is changed and the temporary storage area is empty, diff is compared with "all files in the work area and the warehouse submitted in the last commit";
# When the workspace is changed, the staging area is not empty. diff compares "all files in the workspace and staging area".
git diff
git diff <filename>	# Specify file

# Displays the addition, deletion and modification of all different files between the staging area (files added but not committed) and the last commit(HEAD)
git diff --cached
git diff --staged

# Compare the difference between the last submission of the staging area and the workspace
git diff HEAD
git diff HEAD <filename>	  # Specify file
git diff <Hash value> <filename>	# Specify a submission

# View the additions, deletions, and changes between the last submitted version and the previous X versions of the past timeline and all the files defined in the same git diff HEAD
git diff HEAD~X
git diff HEAD^^^...(Back there X individual^Symbol, X Is a positive integer)

# Compare the contents of the last commit on the two branches
git diff <branch-Name1> <branch-Name2> 
git diff <origin/branch-Name1> <branch-Name2> #Compare remote branch with local branch
git diff <branch-Name1> <branch-Name2> --stat	# Show brief content

git tag is used to create tags

# Create local tag
git tag <tagName>
git tag -a <tagname> -m "XXX..."  # Specify label information

# Push to remote warehouse
git push origin <tagName>

# There are multiple tags in the local area, and all tags are pushed at one time
git push origin --tags

# After switching labels, the branch is set to blank
git checkout <tagName>

# View the details of a local tag
git show <tagName>

# View all local Tags
git tag
git tag -l

# View all remote Tags
git ls-remote --tags origin

# Deletion of local tag
git tag -d <tagName>

# Deletion of remote tag
git push origin <tagName>

Topics: git github