Git status File trace git add XXX // Trace a file git add. // Batch trace files to a local repository git commit // Commit files to a local repository git Commit -m ‘XXX’ // git commit -am ‘XXX’ //

Git pull origin XXX // git pull origin XXX // git pull origin XXX // Pull, if no tracking information is prompted, we can establish a trace by using the following method, Git diff –set-upstream branch-name origin/branch-name git diff –set-upstream branch-name origin Git reflog git reflog git reflog git reflog git reflog

We usually have a dev or other development branch separated from the master branch so that the main branch will not be affected if there is a problem with the development.

Create a new branch using Git branch XXX.

Use Git Checkout XXX to switch to the new branch.

Branch, checkout

Git checkout -b XXX // you can quickly create and switch to a new branch

Git branch -d XXX // When a branch is merged into the master branch, the branch can be deleted with -d

Git branch -d XXX // delete branches that are not merged

Git branch -a // Check all branches

Git branch -vv

Note: When merging branches, you must make sure that you are merging to the target branch of the branch

Git merge XXX to merge the XXX branch into your current branch.

If different branches modify the same part of the same file during branch merge, Git will not be able to determine which branch code should be used, which will cause a conflict. Although Git merges, it is not committed, so we need to resolve the conflict and commit again.

Git status can be used to check which files are in conflict, and then solve them one by one. After fixing the conflicting codes according to the correct code, we need to add, commit, and push again.

Clone a remote repository:

Clone the remote repository with git Clone URL

Git clone github.com/MasonEast/b…

Git clone github.com/MasonEast/b newName

// If you want to put your project files in the current path, add.git clone github.com/MasonEast/b… .View remote warehouse:

The repository we cloned will see a remote repository named Origin through Git Remote, which is the original repository identified by Git default.

Git remote -v or git remote –verbose you can view more detailed information, i.e. the corresponding project address. Normally there are two, but if you do not have push permission, you can only see the address of one fetch.

git remote -v

Origin [email protected]: W-qing/notes.git (fetch) Origin [email protected]: W-qing/notes.git (push) Delete remote branches:

Git push origin: XXX git push origin: XXX

Git remote rm XXX

Git remote rename oldName newName Git remote rename oldName newName Git remote rename oldName newName Git is mainly used for version control and collaborative development.

To remove files from the staging area:

Scenario: Sometimes it is customary to commit all modified files to the staging area using Git add. but some files should not be committed and removed from the staging area.

Git reset HEAD XXX //

Scenario: If we not only add XXX to the staging area, but also commit it to the local repository, only to realize that it is unnecessary and want to retrieve it.

Git rm XXX changes last commit:

Scenario: After a commit, what if there are fewer files or problems with the last committed code? Instead of simply saying “commit again,” it’s more elegant to not commit again, but to modify the commit.

Git add XXX // Add the undercommitted or modified files to the hold git commit –amend // Add the undercommitted files to the last commit and fix the commit information

Git commit –amend –no-edit // shortcut, using the –no-edit parameter, which indicates that the commit does not change and is a single commit on Git. Amend. The last commit is modified by combining the contents of the current commit with the contents in the Stageing area to create a new commit that replaces the current one.

You can then delete the changeId and modify or keep the changeId. Save :wq and press Enter to update your commit.

Tips: There is no problem with the code file just submitted, but there is a problem with the submission information. How should I modify it?

Git commit — amend-m “new commit information” about the pending problem

If you are working on a requirement and suddenly there is an urgent bug that needs to be fixed, you need to stash the code that you have already written and return to the previous COMMIT version. After fixing the bug, you can push the unfinished code out of the cache stack and continue working.

Stash stash list git stash pop stash apply stash@{1 Files that have never been added cannot be stash because Git ignores them. If you want to stash these files as well, you can add the -u argument. It’s short for –include-untracked. It looks like this: git stash -u

Merges a commit from one branch to another

Git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick: git cherry-pick

First, type git log on the master branch to find the commit record to merge, such as commitID: 3fab5dexff. Then switch to the dev branch and use git cherry-pick 3fab5dexff to merge the commit into the dev branch, but only locally. Finally, git pushes commit to the dev remote. At this point, the changes involved in the commit that was accidentally made on the master branch are merged into the remote dev branch. There are several types of submission formats that are commonly used:

Feat. Fix bugs, docs, and refactor. Refactoring (either a new feature or bug fix but a code change to optimize an existing project