Now let’s take a look at what Git does
Git commit steps
git init
Initialize the Git repository in this project foldergit status
Viewing file Status
By default, Git doesn’t know which files need to be managed, so this command can prompt the administrator for files that aren’t managed by Git, prompting the programmer to commit those files.
Git add list of files
Submit the file you want to submit to the staging areaGit commit -m
Commit code to the repository, remember to include the commit instructionsgit log
Viewing the Submission Record
By default, the git folder is hidden, you need to click the “View” button to display the hidden folder.
Git Restore record
What if I accidentally submit the wrong document? This involves some operations that Git does to recover records.
Overwrite the file in your working directory with the file in the staging area: the file git Checkout is restoring
Git rm –cached. Note that this only deletes the files from the staging area. The files in the working directory will still exist.
Git rest –hard commitID where commitID is the version number of the file we want to restore.
Git branch
Think about it: if we need to update the same piece of code, fix bugs, etc., we have to modify it repeatedly in the same file, and then copy and paste it…
This is inhuman!
So is there a better way to solve this problem? Use branches in Git to solve the problem.
Git has a default master branch, the master branch, which acts like a tree trunk and automatically creates new nodes as the commit records are updated. Main branch code is generally used for distribution to the outside world, so development is left to other branches rather than the main branch.
Develop makes a copy of the main branch that develops its own features
The functional branch is merged into the development branch, which is merged into the main branch.
Git branch command
Git branch name: git branch name: git branch name: git branch name Git branch -d git branch -d git branch -d git branch -d
Save your changes for now
Consider this scenario: If you’re working on a new feature on one branch, the other branch has a major bug that needs to be addressed. What if you don’t want to commit the branch you haven’t finished yet?
Do we need a “draft box” to hold branches, so we can save the code for now?
This is when it comes to temporarily saving your changes. Note that if you run this command on another branch, it will revert the change to another branch. Therefore, before you run this command, you need to know which branch you are in. This is equivalent to CTRL + X putting something on the clipboard. And then I’m going to paste CRTL plus V back.