git clone

$git clone -b $git clone -bCopy the code

git config

# --local: storage level, --globalLevels: global, - system: system $git config < - local | -global| - system in effect > - l # to check the configuration information $git config - l # # to edit the configuration file - local: warehouse, -globalLevels: global, - system: system $git config < - local | -global| - system > - e # add configuration item # - local: warehouse, -globalLevels: global, - system: system $git config < - local | -global| - system > add < name > < value > # for configuration items $git config < - local | -global| - system > get < name > # delete configuration items $git config < - local | -global| - system > - the unset < name > # configuration to submit the user information in the record $git config -global$git config -- $git config --globalUser. email < email address > # change the size of Git cache # Change the size of Git cache # Change the size of Git cache # Change the size of Git cache #524288000$git config --globalGit diff < git diff > $git config --global color.ui true$git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.last 'log -1 HEAD'  // Last commitThe password can be cached by default15$git config --globalCredential. helper cache # $git config --global credential.helper 'cache --timeout=< cache time >'$git config -- $git config --global credential.helper store
Copy the code
  • File state change cycle:

git status

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean  // All traced files have not been changed since the last commit

$ echo 'My Project' > README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    README

nothing added to commit but untracked files present (use "git add" to track) Git add is required to trace files

$ git add README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

    new file:   README   // It is in the temporary state

$ git status -s  // Status overview
 M README
MM Rakefile
A  lib/git.rb
M  lib/simplegit.rb
?? LICENSE.txt  // New files added to the staging area are preceded by an A mark, and modified files are preceded by an M mark
Copy the code

git diff

$ git diff  // Compare the difference between the current file in the working directory and the snapshot of the staging area (no changes have been temporarily saved after modification)

$ git diff --staged/cached // Difference between temporary file and last submitted file
Copy the code

git stash

This can be used to stash work in progress, such as when you want to pull the latest code without committing it, or when you want to fix an urgent bug. Stash pop allows you to return to your previous commit and then stash pop allows you to continue your work.Copy the code
Add a cache stack: git stash; Check out the cache stack: git Stash list; Launch cache stack: Git Stash pop; Git stash apply stash@{1};Copy the code

git commit

$ git commit -m ' '
$ git commit -am 'added new benchmarks'
Copy the code

Git rm to delete

$ git rm -f project.md // Remove from the staging area
Copy the code

Git mv mobile

$ git mv file_from file_to
=
$ mv README.md README
$ git rm README.md
$ git add README
Copy the code

Git log to view commit history

$ git log -p -2  // -p or --patch will display the differences introduced by each commit (output in the format of the patch). You can also limit the number of log entries displayed, such as using the -2 option to show only the last two commits

$ git log --stat  // Brief statistics for each submission

$ git log --pretty=oneline // Display each submission on a single line, as well as the short, full, and Fuller options, which display information in roughly the same format, but with varying levels of detail

$ git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \
   --before="2008-11-01" --no-merges -- t/
Copy the code

Cancel the operation

  • git commit –amend

Several files were missed and not added, or the commit information was incorrectly written, use the commit command of the Amend option to resubmit. (Eventually you will only have one submission — the second submission will replace the result of the first.)

$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
Copy the code
  • git reset HEAD fileName

Unmount temporary files (restore commit records)

  • git revert

A new commit is generated to undo a commit, and all commits prior to this commit are retained.

  • git checkout — fileName

Undo changes to a file

In Git anything that has been committed can almost always be recovered, whereas anything that you haven’t committed is likely to be lost and never found again.

Remote warehouse

  • git remote

View the remote warehouse server that you have configured

  • git remote -v

Displays the Git shorthand and URL to use to read and write remote repositories

  • git remote rename pb paul

Renaming of the remote repository

  • $ git remote remove paul

Removals of remote repositories

git tag

$ git tag
$ git tag -l  // List all the tags
$ git tag -a v12. 9fceb02 // Tag (SHA)
$ git tag -d v14.-lw // Delete the label
Copy the code

git branch

$ git branch
$ git branch newBranchName
$ git branch -a // Check the remote branch name$git branch -b branchName $git branch -d branchName $git branch -m// Change the branch name
Copy the code

git reflog

Git reflog allows you to view local operation records, such as commit, merge, and rebase, with version numbers

git merge

$git merge < branch name >Copy the code

git pull

Get the latest version from the remote repository. $ git pull = $ git fetch + git merge $ git pull --rebase//todo
$ git merge --no-ff //todo
Copy the code

git cherry-pick

Merges committed records into the current branch.

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

Git add commits to staging area

Workspace -> git status -> git add. Add all changes to staging -> git commit -m "Commit description" commit code to local repository -> git push update local repository code to remote repositoryCopy the code
  • Scenario 1: Workspace When you have tampered with the contents of a file in your workspace and want to discard the workspace changes directly, use git checkout — file.
    // Discard workspace changesGit Checkout -- < filename >Copy the code
  • Scenario 2: Staging area When you change the contents of a file in your workspace and add git add to the staging area and want to discard the changes, there are two steps. The first step is using the command
    git reset HEAD <file>
    Copy the code

    We are back to scenario 1. Step 2 follows scenario 1.

    // Unstage the staging area and put it back into the workspace.Git reset HEADCopy the code

Git commit to local repository

    1. Error submitting information

    Changing commit Information

    Git commit -- amend-mCopy the code
    1. Leakage to submit

    There are two solutions to this problem:

    Solution 1: Commit again

    Git commit -mCopy the code

    At this point, git produces two commits

    Scheme 2: Missing files to commit before commit

    git add missed-file // missed-file indicates the missed file
    git commit --amend --no-edit
    Copy the code

    –no-edit indicates that the commit message does not change and is a single commit on Git

Commit the error file, roll back to the previous COMMIT version, and commit again

  • Git reset Deletes the specified commit

    // Modify the repository, keep the staging area, keep the workspace
    // Soft rollback of the repository by 1 version. Soft rollback means that the local repository head pointer is reset to the specified version and all changes made after this commit are moved to the staging area.
    git reset --soft HEAD~1
    
    // Modify the repository, modify the staging area, modify the workspace
    // Rolling back the repository by one version not only resets all the header Pointers of the local repository to the specified version, but also resets the staging area and the workspace code to that version as well
    git reset --hard HEAD~1
    Commit_id: commit_id: commit_id: commit_id: commit_id: commit_id: commit_id: commit_id: commit_id: commit_id: commit_id
    git reset --hard commit_id 
    Copy the code
  • git revert

    To undo an operation, the commit and history before and after the operation are retained, and the undo is treated as the latest commit

    // Undo the previous commit
    git revert HEAD
    // Undo the previous commit
    git revert HEAD^
    / / (such as: fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff) revoked the specified version, cancellation will be submitted as a to save.
    git revert commit
    Copy the code

    Git Revert is the process of submitting a new version that you want to reversely revert without affecting the previous version

Git merge git rebase

  • Rebase merges the commit history of this branch with that of other branches, possibly resulting in a new commit history
  • Rebase gets a cleaner project history by removing merge commi, which is not easy to locate if merge code problems occur because re-write the commit history
  • Merge creates new commits, including commit details for each branch
  • Each merge automatically generates a MERGE COMMIT. In particular, if the commit is frequent, the branches are messy.
  • To get a clean, linear commit history without merge commit, select Git Rebase
  • To get a complete commit history and avoid the risk of rewriting the commit history, select Git Merge

Reference: juejin. Cn/post / 684490… Juejin. Cn/post / 684490…