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 command
  • git help add: seegit addThe specific explanation of the command

1.2 Warehouse initialization

  • git init: create.gitIs suitable for adding versioning to existing projects
  • git init projectname: createprojectname/.gitIs 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 filenameThere are temporary
  • git 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 again
  • git rm --cache filename: holds but does not participate in tracking
  • git mv filepath newfilepath: Move files
  • git rm filepath && git add newfilepath: move a file after using a non-git command to move the file
  • git 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, andrmCommand a similar
  • git reset etc...: History commit management (rollback, merge…) , checkout pays more attention to files

1.4 Viewing File Modifications

  • git status: View file information
  • git 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 color
  • git 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 information
  • git log --oneline: Displays the submitted Message
  • git log --stat: Displays the detailed modification information of the file name
  • git log --patch: Displays the content level details of the submitted file
  • git log --graph: Shows submission records with graphs
  • git log --graph --all --decorate --oneline: Redundant information is removed to display each branch submission more intuitively
  • git 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 files
  • git reflog: Modify logs in detail

1.7 Branch Operations

  • git branch branchnameCreate branch
  • git branch: Display branches
  • git branch -d branchname: Delete branch
  • git branch -D branchname: Deletes unmerged branches
  • git checkout branchname: Switch branches
  • git checkout commitID: When the working tree is switched to commitID
  • git checkout -- filename: Clears the last submission
  • git checkout -b branchname: Creates a new branch and enters it
  • git 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 area
  • git merge squash branchname: changes the merged branch to a COMMIT
  • git 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 URL
  • git remote rm origin: delete
  • git remote -v: check the URL
  • git fetch origin: Fetching remote branch, there will be one localremotehostname/branchnameBranch, typically used to view partner code
  • git 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