Bronze player

The typical Git process for a single-person project is the following four steps:

1. Clone the remote project or initialize the local project

First, pull the project code from the remote repository through Git Clone. Of course, if there is no project in the remote repository, git init can be used to directly initialize the project locally.

2. Submit documents to the temporary storage area

Git add. Simple and simple, commit all the modified files and contents to the staging area;

3. Submit the files in the staging area to the local repository

Commit the contents of the staging area to the local repository with git commit -m ‘commit some notes here’;

4. Synchronize the data from the local warehouse to the remote warehouse

Push local branch code to remote repositories via Git push;

At this point, a simple process of uploading code changes to a Git repository (ideal for solo development) is over, so let’s get some food and energy.

    Clone the project or initialize the Git repository locallyGit clone or git init// Commit all changes to the staging area
    git add .
    // Commit all code for the staging area to the local repository
    git commit -m 'Code remarks'
    // Commit the local repository code to the remote repository
    git push
Copy the code

The silver player

So the question is coming, when you meet the people development can’t keep everyone on the master branch development code, if two people at the same time submit code, and change to the same file, there will always be all sorts of conflicts, submit code every time have conflict, wouldn’t it be 🥚 ache, for development efficiency is very low, so it is very necessary for multiple branches;

The new branch

    // Create your own local development branch dev
    git branch dev
    // View all local branches
    git branch
    // View all remote branches
    git branch -r
    // View all branches (local + remote)
    git branch -a
    // Delete the dev branch
    git branch -D dev
    // Rename the branchGit branch -m < old > < new >Copy the code

Switch branch

    // Switch to the local dev branch
    git checkout dev
    // Create a local dev branch and switch to it
    git checkout -b dev
Copy the code

Git checkout -b dev is a combination of git branch dev and Git checkout dev.

Merging branches

Git mergeCopy the code

Submit documents to the staging area

    // Submit all files
    git add .
    // Submit a single fileGit add < filename >Copy the code

Submit staging area files to local repository

    // When submitting, open the PC's own editor to add remarks
    git commit 
    / / submit
    git commit -m 'Submit notes'
    Git add. // git commit -m
    git commit -am 'Submit notes'
    // If you are not satisfied with the previous commit information, you can modify the previous commit remarks, but also modify commitId
    git commit --amend
Copy the code

Pull the code

    // Pulling changes from the remote side does not change the local codeGit fetch < remote host name >Git fetch // git mergeGit pull < remote host name > < remote branch >:Copy the code

In a short while, and consume a lot of brain cells, and find something to go!

Gold players

These git operations can greatly improve your development efficiency;

    git push -u origin master // Bind the tracing relationship between local and remote branches
    git stash // Hold the code you don't want to commit
    git log // View the commit logs
    git tag // Check the version of the tag
    git status // Check the current status

Copy the code

git push -u origin master

    // If the current branch is traced to multiple hosts, you can specify a default host with the -u parameter,
    // Git push can be used without any arguments
    git push -u origin master
Copy the code

Git push -u origin master git push master git push master git push master git push master git push master Git 2.0 used matching by default. Now it’s simple. If you want to change your Settings, you can use Git config. Git config –global push.default matching OR git config –global push.default simple; You can use git config -l to view the configuration

git stash

I have developed some code locally, and I have to switch to another branch to fix it, but I don’t want to commit the code I just developed, so I can temporarily save it to the git stack, then switch to another branch to fix it, and finally pop it back to this branch to continue development

    git stash // Store local changes temporarily
    git stash save "message"During storage, add remarks for easy search. git stash pop// Apply the last temporary change and delete the temporary record
    git stash apply // The first stash is used by default, stash@{0}, and stash@{$num} is used by default.
    git stash list // See what stash stores are
    git stash clear // Remove all cached stash
    
Copy the code

git log

    git log --oneline // This command simplifies the default git log output to only output the first 7 strings of the commit hash and the commit message.
    git log --oneline --number // only one row is displayed for each log.
    git log --oneline --graph // The branch merge history can be graphically represented.
    git log --oneline branch1 ^branch2 // you can view submissions that are in branch 1 but not in branch2.^ indicates that the branch is excluded.

    git log --stat // Add/delete/add/delete/add/delete/add/delete/add/delete
    git log -p // Control the output of the specific modifications for each commit in the form of diff.
    git show The git show command is similar to the git log -p output, except that it displays only a commit. If you do not specify a commit hash, it defaults to HEAD pointing to the commit.

    git shortlog // It is used to output summary information, categorized by author
    git shortlog -s // Can be used to count the number of commits per author
    git shortlog -n // Can be used to calculate the quantity in reverse orderGit log// Displays logs for specific branches.Git log --since --before --until --after git log --after '9-3-2021'// Filter log git log --no-merges indicates that merge commits are excluded Git log --grep=<commit information > // Filter logs based on the commit informationCopy the code

git tag

    git tag // Check the tag version
    git tag -r // View the remote tag version
    git tag <name> // Create the tag version
    git tag -d <name> // Delete the tag version
    git push origin <name> // Create a remote tag version
    git push origin --tags // Upload local tag to remote
    git pull origin --tags // Merge remote tags to local
    git push origin :refs/tags/<name> // Delete the remote version
Copy the code

git status

Git status -v, --verbose git status -s, --short git status -b, --branch displays branch information git status --show-stash Displays cache information git status -- Ahead-behind computs complete lead/lag values git status --long Displays status in a long format (default) git  status -z, --nullEntries end with NUL charactersCopy the code

More and more things, first go to eat a big meal, come back to continue!

Platinum players

At this level, there are some problems with the code on the branch, which must be reversed or deleted. At this time, it is very troublesome to modify the code line by line.

git reset // Code reset
git revert // Code rollback
git merge // Code merge
git rebase // Code base change
Copy the code

Rollback and reset

Imagine that one day, there is a requirement change in the product. At this time, you change a piece of code in a dev1 branch, and you are ready to launch. Suddenly, the product requires that the requirement is temporarily not available. However, after changing that code, there are many more commit times. Some of them forget where they changed. What should I do? The first way: honestly to find that all the content of the changes, and then compared to the same change back, of course this way is more troublesome, time consuming, the second way: roll back the one commit submit, in that commit to submit before and after the submission does not affect, solved a line command, perfect!

git revert // Undo an operation that does not modify the original commit record, but adds a new commit record to cancel the operation.
git revert <commit-id> // For normal commit
git revert <commit-id> -m // Commit for merge
// Revert can also roll back multiple COMMIT
git revert [commit-id1] [commit-id2] ...Note that this is an open before closed interval, meaning that commit1 is not included, but COMMIT2 is included.Copy the code

There are two ways to rollback a commit. You can also use git reset to undo your commit.

Git Revert will create a commit message to undo the changes.

Git reset returns the commit directly to the specified COMMIT. For individual feature branches, you can use git reset to roll back the history, and then use git push –force to push the history to the remote branch. However, it is not recommended to use git reset directly on multiple collaborative integrated branches. Instead, use the more secure Git Revert command to undo the commit. In this way, the submitted history is not erased and can be safely withdrawn.

Git merge and get rebase

This I do not introduce more, see big guy this article is enough, write very detailed, I also learned a lot of dry goods;

Git merge and rebase merge commands

Masonry players

Unfathomable technology still needs to be discovered…

reference

www.cnblogs.com/qianqiannia…

Juejin. Cn/post / 697418…

Blog.csdn.net/dengsilinmi…