The foreword 0.
In the use of Git has a feeling that will only add | commit | push three commands. Because these three commands seem to be enough to get your code submitted to GitHub, even if you run into a problem, you can just Google it. But for the logic and the essence of version management did not realize, but merely used as an online code in warehouse, it also have no what can’t, but if you can understand why do you want to have a version of the system management tools, as well as the version management tools can provide us how management services, are of great help for our use tools. You don’t have to remember the command, it’s just enough to know that the tool has a way to implement it if you run into problems later.
Now I have taken a systematic look at the official Git introduction tutorial (Chinese characters). In the Git official tutorial (Chinese characters), I choose the operation mode of the command by describing the use situation of the command, making the command easy to understand and deepen the memory. This is more friendly to people unfamiliar with Git than a single command being explained in text. However, it is easy to forget after reading, so I wrote this collation note as an auxiliary query.
1. Basic commands
1.1 Understanding help Commands
git help
: View commandgit help add
: seegit add
The specific explanation of the command
1.2 Warehouse initialization
git init
: create.git
Is suitable for adding versioning to existing projectsgit init projectname
: createprojectname/.git
Is suitable for adding version control at the beginning of a project
1.3 Basic Operations on Files
git add filename/*
: Add file [generate temporary file]git commmit -m "message"
: Commit the added file to the local repository [generate the commit file]git rm filename
: Removes the file and usesrm filename
There are temporarygit add -u .
If you have previously used a non-git command to delete files, you can use this command to delete files in the current directory againgit rm --cache filename
: holds but does not participate in trackinggit mv filepath newfilepath
: Move filesgit rm filepath && git add newfilepath
: move a file after using a non-git command to move the filegit add -A .
If you used a non-git command to move files, you can use this command to move files in the current directory again, andrm
Command a similargit reset etc...
: History commit management (rollback, merge…) , checkout pays more attention to files
1.4 Viewing File Modifications
git status
: View file informationgit diff
: View modifications [working tree and temporary files]git diff --staged
: View modifications [temporary files and recently committed files]git diff HEAD
: View modifications [working tree and recently committed files]git diff --word-diff
: See modified words in colorgit diff --stat
: View the modified file name
Git Add & Commit learn about Git repository implementation
1.5 Viewing the Submission Log
git log
: Displays the submission informationgit log --oneline
: Displays the submitted Messagegit log --stat
: Displays the detailed modification information of the file namegit log --patch
: Displays the content level details of the submitted filegit log --graph
: Shows submission records with graphsgit log --graph --all --decorate --oneline
: Redundant information is removed to display each branch submission more intuitivelygit log --stat -- filename
: File submission record (do not record path movement)git log --stat -M --follow -- filename
: See the complete file operation process
1.6 Ignoring Files
touch .gitignore
: Create files (subdirectories can also be created)vim .gitignore
: Edit file and add file ignore.*.log | tmp/ | .sass-cache etc...
git ls-files --others --ignored --exclude-standard
: View the ignored filesgit reflog
: Modify logs in detail
1.7 Branch Operations
git branch branchname
Create branchgit branch
: Display branchesgit branch -d branchname
: Delete branchgit branch -D branchname
: Deletes unmerged branchesgit checkout branchname
: Switch branchesgit checkout commitID
: When the working tree is switched to commitIDgit checkout -- filename
: Clears the last submissiongit checkout -b branchname
: Creates a new branch and enters itgit merge branchname
: and branch branchname to current branch (file conflicts must be resolved manually during merge)git merge --abort
: Clears the working directory and staging areagit merge squash branchname
: changes the merged branch to a COMMITgit rebase branchname
: Merges the current branch history commit into branch branchname
Resources 2. Code merging: Merge, Rebase options
1.8 Remote Operations
git remote add origin https://github.com/accountname/projectname
git remote set-url origin newUrl
: change the URLgit remote rm origin
: deletegit remote -v
: check the URLgit fetch origin
: Fetching remote branch, there will be one localremotehostname/branchname
Branch, typically used to view partner codegit pull origin
: Is similar to fetch, but fetches remote updates and local merges. This is equivalent to fetch and then merge.git push origin
: Push to the remote warehouse
1. Git remote operation detailed
2. To summarize
In fact, before starting to learn down the entire Git command process, the understanding of Git is very simple, and the use of the command is also holding the mentality of try, wrong search solution retry, on the cause of not to investigate. This approach feels more time consuming and is likely to be repeated multiple times. I feel that after learning something, I still have to understand the whole system. I want to get started quickly, but I should ask why more when I am idle. With a macro concept, I may find a solution to the problem. Another thing is that practice is actually more memorable than just reading or watching a video. The same goes for understanding commands, so it’s best to type them all over again.
- GitHub
- Blog
- The Denver nuggets
Thanks for reading ^_^
3. References
- -1. Get started with GitHub&Git
- Git add & Commit
- 1. Detailed Git remote operation
- 2. Code Merge: Select Merge and Rebase
- 3. High quality Git Chinese tutorials on GitHub