The Git download
Git is a free, open source distributed version control system designed to handle everything from small to large projects quickly and efficiently. Git is easy to learn, has a small footprint, and lightning fast performance. It has SCM tools like Subversion, CVS, Perforce, and ClearCase, inexpensive local branches, convenient staging areas, and multiple workflows.
configuration
git config --global "Your Name"
git config --global "Email Address"
Copy the code
Initialize the
git init
Copy the code
Commit changes
Git add <file> git add -u Commit all tracked files in the work directory to staging area git commit -m "Descriptions" git commit --amend Modify the last commit git commit --amend --author "user_name <user_email>" Modify the last commit user name and emailCopy the code
View status and comparison
Git status git status -s Thumbnail information about file status, common A: new. M: File changes; ? : not track; Git diff --check <file> git diff --check <file> git diff --check <file> git diff --check <file> git diff Diff --cached <file> view the added content (green M)Copy the code
View historical versions and operations
Git log git reflog git log -n Last n commit history git log <branch_name> -n Branch branch_name last n commit history git log --stat Last commit file changes git Log --shortstat --stat only displays the last total file and line change statistics (n file changed, n insertions(+), N deletion(-)) git log --name-status Displays the list of new, modified, and deleted files. Git log lhs_hash.. Rhs_hash Compares two commit changes (LHS is added or deleted, such as git log HEAD~2.. HEAD == git log HEAD -3) git log -p add/delete git log -p -w Add/delete git log Git log origin/ ei-1024-1 --stat -p -w Git log origin/master.. Git log <branch_name> git log <branch_name> --graph Git log <branch_name> -- dedicate references to commit histories, such as tags, Git <branch_name> --oneline --graph --decorate Git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen%ai(%cr) %C(bold) <%an>%Creset' --abbrev-commit It is recommended that alais save git log --pretty=format common option (excerpt from progit_v2.1.9) %H commit full hash %H commit short hash %T tree full hash %T Short hash string of tree object %P Full hash string of parent object %P short hash string of parent object %an author's name %ae author's email address % AD author's revision date (can be customized with the --date= option) %ar How long ago did the author update the date to display % CN committer name % CE committer email address % CD submission date %cr submission date, Git log --since --after Commits after --until --before Commits before --author Displays the commit git of the specified author - display 4-8 committers submission specified (note: committers is not necessarily the author) the git log -s [keyword] show only the add or remove a keyword submit (some scenarios than the git log - p | grep Git log origin/b3.3/master --author=yx-ren --since="2019-10-01" --before="2019-11-01" Git log origin/b3.0/master --author=some_leave --since="1 month ago" Git log --since=1.weeks git log --since=1.days git log --since=1.weeks -- Since ="1 weeks 2 days 3 hours 40 minutes 50 seconds ago" -- Since ="1 weeks 2 days 3 hours 40 minutes 50 seconds agoCopy the code
Version rollback or forward
Git reset --hard HEAD^ Rollback to the previous version git reset --hard HEAD~5 rollback to the previous version git reset --hard id rollback to the specified versionCopy the code
Undo modify
Git add/commit git restore <file> Git add/commit git reset HEAD <file> Git commit: Commit the file by mistake (once committed, you can only undo it by version rollback)Copy the code
Delete and Restore
Git rm/add <file> git commit -m "remove <file>" Git checkout -- <file> Restore workspace <file> from <file>Copy the code
Clean up your workspace
Files or folders without track or ignore (such as temporary.swp,.patch files, etc.)
Git clean clear - I # interactive, not commonly used git clean - n # to check the clean file list (not including folder), not the actual cleaning action git clean - n - d # to check the clean file list (including folder), Git clean -f # delete all untracked files and folders git clean -df # delete all untracked files and foldersCopy the code
Associate the GitHub remote repository
Local to remote
Git remote add origin <remote address> Associate git remote rm origin with git push -u origin master as prompted in the local workspace directory Git push origin master <remote address>: [email protected]:<username>/<repository>.git https://github.com/<username>/<repository>.gitCopy the code
Clone GitHub remote repository
Remote to local
Git clone <remote address> The git protocol is faster but not supported on the Intranet. The HTTPS protocol is slowerCopy the code
Branch management
Create, switch, view, merge, delete
Git branch <branch name> <branch name> Git checkout -b <branch name> create and switch to <branch name> branch git switch -c <branch name Git branch -d <branch name> Delete the branchCopy the code
Resolving merge conflicts
Error "branch conflict" is reported in merge. First, vim corresponding file, modify the conflict location, then follow git add/commit to commit again, and finally delete redundant branches. git log --graph --pretty=oneline --abbrev-commit git log --graphCopy the code
Branch management
Deleting branches after merging also keeps branch records in the log
git merge --no-ff -m "descriptions" <branch name>
Copy the code
The development process
Dev dev dev dev dev dev dev dev dev dev dev Dev Dev Dev Dev Dev Dev Dev DevCopy the code
References
https://git-scm.com/book/en/v2
Copy the code
\