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
- Reference installation Git detailed installation tutorial
- Reference video The latest Git tutorial at station B is easy to understand It's a little long, and I don't feel like much.
- Reference video Git knows that's enough_ Beep beep beep_ bilibili This is the essence. I recommend this.
- Reference video 7 hours to learn a complete set of Git basic tutorials (from introduction to mastery)_ Beep beep beep_ bilibili Although this one is long, he is practical and friendly to Xiaobai, which is very interesting
- Attached is a Git animation learning website
- Git tutorial - Liao Xuefeng's official website (liaoxuefeng.com)
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.
- cd change directory
- cd . . Go back to the previous directory and directly CD into the default directory
- Start < filename > open file
- Cat < file name > displays the contents of the file in the command window
- VIM < file name > edit the file in the command window and press "Esc" to enter ": wq" to save the file: e! "Discard changes
- pwd displays the current directory path
- ls(ll) lists all the files in the current directory, but LL (two ll) lists the contents in more detail
- Touch creates a new file, such as touch index JS will create a new index in the current directory JS file
- rm deletes a file, rm index JS will put index JS file deleted.
- mkdir to create a new directory is to create a new folder
- rm -r delete a folder, rm -r src delete src directory rm -rf / do not try in Linux! Delete all files in the computer!
- 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
- reset reinitializes the terminal / clear the screen.
- clear screen
- History view command history
- Help help
- Exit exit
- '#' 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>