Column catalog

  • GIT is introduced
  • GIT differences
  • The GIT command
  • Common mistakes
  • General scenario

Column details

GIT is introduced

Git (gIT-SCm.com/) is an open source distributed version control system designed by Linus Torvalds to help developers, most of whom will choose Git as your code management tool.

  • Branch: A subbranch that is separated from the master so that operations do not affect the master branch
  • Merge: You merge branches when changes to the subbranches need to be merged into the master
  • Conflict: A conflict occurs when the same file is modified and merged by different branches. You need to manually resolve the conflict
  • Repository: A repository is where you keep your code after you submit it. We have both remote and local repositories

GIT differences

Git and other main difference is that the Git version control system change only care about whether the file data as a whole, while most other systems only care about the specific differences of file content, these systems (CVS | Subversion | Perforce | Bazaar…). Each time, record what files have been updated and what has been updated.

Git does not save these changes before and after difference data, and Git is more like the change after the file as a snapshot record in a built-in file system, it will not be presented updated with all the files of fingerprint information and make the snapshot to the file, and then save a pointer to the snapshot of the index, if the file does not change, just keep the last snapshot of the link.

Most operations in Git require only access to local files and resources without a network connection, but with CVCS, almost all operations require a network connection, because Git keeps all the historical commits of the current project on the local disk, so processing is extremely fast.

All data is checksum before it is saved to Git, and this result is used as the unique identifier and index of the data. In other words, Git cannot change a file or directory without knowing it. This feature, as Git’s design philosophy, is built at the very bottom of the architecture, so Git knows immediately if a file becomes incomplete during transfer or if the disk is corrupted and the file data is lost. Use the GitSHA-1Checksum algorithm to calculate the data, based on the contents of the file or directory structure to calculate a hash value, SHA – 1 as a fingerprint string, the string by 40 hexadecimal character (0-9 | a – f), in fact all things are held in the Git database with the hash value for the index, not by file name.

For any file, there are only three states in Git:

  • Committed: Indicates that the file has been safely saved in the local database
  • Modified: A file has been modified but has not been committed for saving
  • Staged: Put modified files in a list to be saved for the next commit

Here we see three working areas for file flow when Git manages projects:Working directory | Staging area | Local repository

Click here for the original official website

The GIT command

Based on the three workspaces, we actually have one moreRemote warehouse, the same as the local repository, except that the repository location is expanded from the local server to the remote server.

Command Descriptions
git add -i Open an interactive interface to add files as required
git add -p Multiple variations of the same file are submitted in different times
git add -u Adds local (modified, deleted, no new) files to the staging area
git add .

git add -A
Adds all files from the current directory to the staging area
git add [DirName] Adds the specified directory to the staging area
git add [FileName] … Adds the specified file to the staging area
git archive Generate a publishable package
git blame [FileName] Displays information about who modified the specified file and when
git branch –set-upstream [Branch] [RemoteBranch] Establishes a trace relationship between an existing branch and the specified remote branch
git branch –track [Branch] [RemoteBranch] Create a branch to establish a tracing relationship with the specified remote branch
git branch -a List all branches
git branch -d [Branch] Forcibly deleting a branch
git branch -m [OldName] [NewName] Local branch renaming
git branch -r List all remote branches
git branch [Branch] [Commit] Create a branch that points to commit
git branch [Branch] Create a new branch without switching
git branch View all local branches
git checkout – Switch to the previous branch
git checkout –track origin/dev Switch to the remote dev branch
git checkout -b [Branch] [tag] Create a new branch that points to a tag
git checkout -b [Branch] Create a new branch and switch to it
git checkout . Restores all files in the staging area to the workspace
git checkout [Branch] Switch to the specified branch and update the workspace
git checkout [Commit] [File] Restores the specified file of a COMMIT to the staging area and workspace
git checkout [FileName] Restores the specified file in the staging area to the workspace
git checkout [BranchName] Switch branch
git cherry-pick [CommitID] Use to apply commit changes from another local branch to the current branch
git clone [URL] Clone the code corresponding to the project URL to the local
git commit –amend -m [message] If no new changes are made to the code, the commit information from the previous commit is overwritten
git commit –amend [file1] [file2] … Redo the previous commit, including new changes to the specified file
git commit -a -v General submit command
git commit -a Submit all changes to the current repos
git commit -am [message] Submit workspace changes directly to the warehouse district and add the submission description
git commit -m [message] Submit the temporary storage area to the warehouse district and add the submission description
git commit -v All diFF information is displayed upon submission
git commit [file1] [file2] … -m [message] Submit the file specified in the staging area to the warehouse district and add the submission description
git commit submit
git config –global alias.ci commit

git config –global alias.co checkout
Set an alias for the git command
git config –list Display Git configuration
git config -e [–global] Edit Git configuration files
git config -l Viewing the Current Configuration
git config [–global] user.name “[userName]”

git config [–global] user.email “[email]”
Setting User Information
git diff –cached [file] Shows the difference between the staging area and the previous COMMIT
git diff –cached

git diff –staged
See updates that have not yet been committed
git diff –shortstat “@{0 day ago}” Displays how many lines of code you wrote today
git diff –staged See the difference between a staged file (stage) and an uncommitted file
git diff –stat View display summary results (file list)
git diff HEAD Shows the difference between the workspace and the latest commit for the current branch
git diff [first-branch]… [second-branch] Shows the difference between the two commits
git diff Shows the difference between the staging area and the working area
git fetch [remote] Download all changes to the remote repository
git fetch If the latest version is obtained from remote to local, merge is not automatically implemented
git init [dirName] Create a new directory and initialize it as a Git local repository
git init Create a local Git repository in your current directory
git log –follow [file]

git whatchanged [file]
Displays the version history of a file, including file name changes
git log –graph Displays information such as when branches and merges occurred
git log –oneline One log in a row
git log –stat Displays the COMMIT history and the files that have changed for each commit
git log -3 View the previous three changes
git log -N –pretty –oneline Displays N past commits
git log -S [keyword] Search submission history, based on keywords
git log -p [file] Displays each diff associated with the specified file
git log -p View the details
git log [tag] HEAD –grep feature Displays all changes after a commit, whose commit notes must match the search criteria
git log [tag] HEAD –pretty=format:%s Displays all changes after a commit, with each COMMIT occupying one row
git log Displays the version history of the current branch
git ls-files Look at what’s already been submitted
git merge –abort Try to fall back to the state before the merge (may fail)
git merge –no-ff <branch_name> The no fast forward merge mode is adopted, and a new COMMIT is generated during the merge
git merge –squash <branch_name> To merge the target branch without carrying commit information, a commit is required
git merge [branch] Merges the specified branch into the current branch
git mv [file-original] [file-renamed] Change the file name and put the name in the staging area
git pull –rebase Staging local changes, merging remote latest changes, merging local changes that have just been staging (synchronization that does not create useless merges)
git pull [remoteName] [localBranchName] Pull the remote warehouse
git pull origin –tags Merge the remote repository tag to the local
git pull Obtain the latest version from remote and merge it to local
git push –all origin Push all local branches to the Origin master
git push -f origin -f force a non-fast-forward merge on the remote host.
git push -u origin master -u specifies origin as the default host, and then you can use Git push without any arguments
git push [remoteName] –delete [branch]

git branch -dr [remote/branch]
Deleting a remote branch
git push [remoteName] :refs/tags/[tagName] Deleting a Remote Tag
git push [remoteName] [localBranchName] Push remote Warehouse
git push [remote] –all Push all branches to the remote repository
git push [remote] –force Forcibly push the current branch to the remote repository, even if there is a conflict
git push [remote] –tags Submit all tags
git push [remote] [branch] Upload the specified local branch to the remote repository
git push [remote] [tag] Submit specified Tag
git push origin –tags Upload the local tag to the remote repository
git push origin :heads/[name]

git push origin :[name]
Deleting a remote branch
git push origin :refs/tags/[name] Deleting a remote version
git push origin master:hb-dev Associate the local library with the library on the server
git rebase –abort When rebase is terminated, the branch returns to the state it was before rebase began
git rebase –continue After the conflict is resolved after the rebase command is executed, the apply command continues to apply the remaining patches
git rebase –skip Skip the current commit
git reflog Displays the last commits of the current branch
git remote -v Display all remote repositories
git remote add [shortname] [url] Add a new remote repository and name it
git remote rm [name] Deleting a remote repository
git remote set-url –push [name] [newUrl] Modifying a remote repository
git remote show [remote] Displays information about a remote repository
git remote show Viewing remote libraries
git reset –hard [commit] Reset the HEAD of the current branch to commit, and reset the staging area and workspace to coincide with commit
git reset –hard Go back to a version completely, replace the staging area and workspace, and the local source will be changed to the contents of the previous version
git reset –keep [commit] Reset the current HEAD to specify COMMIT, but leave the staging area and workspace unchanged
git reset –mixed Just like git Reset with no parameters, resets the staging area without changing the workspace
git reset –soft HEAD~3 The reference is rolled back three times (the workspace is unchanged, the staging area is unchanged)
git reset –soft Go back to a version without changing the staging area or workspace (if you still want to commit, just commit
git reset HEAD The HEAD effect is the same as above, because a reference reset to HEAD is equivalent to no reset
git reset HEAD^ The reference is rolled back once (the workspace remains the same, the staging area is rolled back)
git reset [commit] Reset the pointer to the current branch to specify COMMIT, and reset the staging area, but the workspace remains the same
git reset [file] Resets the specified file in the staging area, the same as the last COMMIT, but the workspace remains the same
git reset Remove from the staging area what was previously added to it by the git add command (the reverse of git add -a)
git revert -n HEAD Undo last time but do not commit
git revert -no-edit HEAD Undo the previous one and use the default comment directly
git revert HEAD Undo previous COMMIT
git revert [commit] Create a NEW COMMIT to undo the specified commit

All changes to the latter will be offset by the former and applied to the current branch
git rm –cached [file] Stops tracing the specified file, but the file remains in the workspace
git rm -r [floder] Deleting a folder
git rm [file1] [file2] … Deletes the workspace file and places the deletion into the staging area
git shortlog -sn Displays all users who have submitted, sorted by the number of submissions
git show –name-only [commit] Displays files that have changed during a particular commit
git show [commit] Displays metadata and content changes for a particular commit
git show [commit]:[filename] Displays the contents of a file at the time of a commit
git show [tag] Viewing Tag Information
git stash apply Restore the latest saving progress, but do not delete
git stash clear Delete all
git stash drop To delete a progress, delete the latest one by default
git stash list Display progress list
git stash pop Restores the latest saved progress and deletes the restored progress from the stored list
git stash push Push the file into a temporary space
git stash save “message” Save the progress with instructions
git stash Save the current progress
git status –ignored Displays ignored files
git status -s Output the results in a short form
git status Viewing the Current Status
git submodule add [url] [path] Adding a submodule
git submodule init Initialize the submodule
git submodule update Update submodule
git tag -a [name] -m ‘yourMessage’ Create the annotated tag
git tag -d [tag] Deleting a Local Tag
git tag -r Viewing the remote version
git tag [name] Create a version
git tag [tag] [commit] Create a new tag and specify commit
git tag [tag] Create a tag in the current commit
git tag List all tags
git version Get git Version

Common mistakes

Authentication failed
# plan a
git config --system --unset credential.helper

# 2-> Win +R open a command window -> Enter Control -> User Accounts -> Manage your credentials -> Windows Credentials -> Find the credential corresponding to the Git address to change the account passwordCopy the code

General scenario

Poke me for details