Here is a record of the more classic Git usage, easy to find. Under ongoing maintenance... Recently modified 2020-9-16 added logCopy the code

branch

$git branch -a
Copy the code

Displays all local and remote branches

$git branch -d <branch name>
Copy the code

Delete the branch

checkout

$git checkout -f 4997f70 -- .
Copy the code

To roll back to a version, the rolled back item appears as a new commit, can be committed, and then pushed to the public branch

$git checkout - readme. TXTCopy the code

Discards modifications to a file

$git checkout -b githubmaster remotes/origin/master
Copy the code

Checkout remote master branch to local githubmaster

$git checkout -b dev
Copy the code

Pulls the dev branch from the current branch

pull

$git pull origin master
Copy the code

Retrieve code from the remote Origin/Master branch and merge it into the current branch

push

$git push origin master
Copy the code

Commit the current branch to the remote Origin/Master branch

The user name

Different projects use different usernames

Git $CD. Git $open config = $open config = $open config = $open config = $open config = $open config

[user] name = XXX email = XXXXCopy the code

Save, command+s. At this point, the project is configured with a separate user name and email address. When the code is submitted, the name is displayed in the commit log. Github will set the user name based on the configured email address. You can also set a separate git configuration from the command line (i.e. remove the –global parameter), just in the.git folder. For example, run the following command: $git config user.name “XXXXX” to change the user name used for submitting the project code. Ps: If the global configuration has the same configuration option as the individual configuration of the current project, for example, if user.name is set for both the global and the project, then the git operation in the project will use the configured user name of the project by default.

If you want to set the same user name to submit to Github, set it as follows

$git config user.name "<github-username>"
$git config user.email "<github-user-email>"
Copy the code

Cherry-pick

Cherry-pick, as its name suggests, picks and chooses the commit we need. It can be used to migrate commit changes made on other branches to the current branch.

$git cherry-pick <commit-id>
Copy the code

Change the author of commit

Execute the following script

#! /bin/sh git filter-branch --env-filter ' OLD_EMAIL="[email protected]" CORRECT_NAME="zhongyongsheng" CORRECT_EMAIL="[email protected]" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tagsCopy the code

log

Print out all the commit records for a branch, showing only one line (no details) and no records for the merge

$git log origin/<branch name> --oneline --no-merges
Copy the code