Submission guidelines

Keep submissions clean

1. Do not commit useless changes

Do not format the code as a whole. In principle, the coding style of a project should be consistent, but it is inevitable that individual configurations will lead to differences.

2. Logically independent change sets

One issue should be submitted at a time. Do not put several changes in the same submission. This ensures that the submitted documents are all for the same function point or problem, which can be submitted for review or back up and selection later.

Storage and cleaning

Sometimes, after you’ve been working on one part of a project for a while, everything goes into disarray, and that’s when you want to switch to another branch and do something else. The problem is, you don’t want to create a commit for a half-done job just because you’ll come back to it later. The answer to this is the git stash command.

Git Stash handles the dirty state of the working directory — that is, tracking file changes and temporary changes — and then stores the unfinished changes on a stack where you can reapply the changes at any time with git Stash Apply (even on a different branch).

Viewing the cache list

git stash list
Copy the code

delete

git stash drop
Copy the code

Only unstored files are stored

git stash --keep-index
Copy the code

Stored files contain untracked

Git stash -u git stash -a contains the ignored filesCopy the code

Clean up your Workspace

-d removes all untraced files and empty subdirectories from the working directory, and -n displays the files to be removed.

The git clean command removes only untracked files that are not ignored. Any files that match the pattern in.gitignore or other ignored files will not be removed. If you also want to remove those files, you can add a -x option to the clean command.

It is easier to use -i to enter interactive command operations

 git clean  -i
Copy the code

Senior merger

Cancel the merger

To repair

Git reset –hard HEAD~ after git merge can reset the branch if it only exists in the local repository.

Reduction to submit

An option to generate a new commit that will undo all changes made to an existing commit

git revert -m 1 HEAD
Copy the code

The -m 1 flag indicates the parent that “mainline” needs to be retained.

Merge the branch after restore will show that it is up to date because all differences have been merged. To merge a branch again restore undo 😵,git revert < commit >

Configure git

Configure the global user name and mailbox

git config --global user.name <name>
git config --global user.email <email>
Copy the code

Git hooks

Submit workflow hooks

Cooperate with ESLint, commitLint, etc to check the code commit format.

  • The pre-commit hook runs before the commit information is typed. It is used to check for snapshots that are about to be committed, for example, to see if anything is missing, to ensure that tests are running, and to verify code. If the hook exits with a non-zero value, Git will abandon the commit, but you can get around this by using Git commit –no-verify. You can use this hook to check whether the code style is consistent (running a program like Lint), whether trailing whitespace characters are present (the built-in hook does that), or whether the new method is properly documented.

  • The prepare-commit-msg hook runs before starting the commit message editor and after the default message has been created. It allows you to edit the default information that the submitter sees. This hook receives options for the path of the file that holds the current commit information, the commit type, and SHA-1 verification for the commit that fixes the commit. It’s not useful for general submissions; However, it is useful for commits that automatically generate default information, such as commit information template, merge commit, compress commit, and revision commit. You can use it in conjunction with the submission template to dynamically insert information.

  • The commit-msg hook takes an argument, which is the path to the temporary file that holds the current commit information, as mentioned earlier. If the hook script exits with a non-zero value, Git will abandon the commit, so it can be used to verify project status or commit information before the commit passes.

  • The post-commit hook runs after the entire commit process has completed. It doesn’t take any arguments, but you can easily get the last commit by running git log-1 HEAD. This hook is typically used for things like notifications