Git add to workspace and rollback
🌵1.1- Submission Process:(Omitted during git installation)
-
Create a new folder and go to folder A for git initialization (git init).
-
The directories are as follows (the three files were submitted in three versions in turn) :
01GitLearn ├─ Index.html ├─ yuefan.html ├─ class.txtCopy the code
-
-
Create a new file in the folder: index.html; When git status is executed on the command line, the index.html file name is red.
-
Git add.: Add all files in the folder to the staging area
-
Git commit -m “Commit info” : commit a file from the staging area to the repository.
-
Git log: you can view the submitted logs and version information.
-
- To exit git log, press in the English input mode
q
- To exit git log, press in the English input mode
1.2 – rollback:
- You can view the multiple version numbers that have been committed using git log in your project directory
- Run git reset –hard + to rollback the version commit information
- After the rollback, you can only view the previous two versions in git log.
- So how do you roll past, like a pendulum, and come back again?
- Git reflog is used to check the submitted version
- Proceed with git reset –hard + version information, and restore the previous version
See the following figure for more complete operation commands such as switching back:
2. The branch:
-
Create a branch: Git branch + branch name
-
Check out the branch: Git Branch
-
Git Checkout + branch
🐳 Now the master suddenly has a bug on the main branch, and the new feature is still under development. How to switch the bug on the fix line without affecting the existing development content?
-
Git checkout master: Go from an existing branch to the master branch
-
Git branch fixbug: Create a branch that fixes the bug
-
Git Checkout fixbug: Switch from the master branch to the master branch to fix bugs
-
Git branch -d fixbug: Deletes the fixbug branch
- in
fixbug
That’s done on the branchbug
And then we have alpha and betamaster
The main branch is merged, and then look at the following merge tomaster
Operation:- Step one. – We have to switch back
Master: Git checkout master
- Step 2 – Merge fixbug branches to master:
git merge fixbug
- Step 3 – Fix bugs if they don’t work, remove them
fixbug
Branches:git branch -d fixbug
- Step one. – We have to switch back
- in
-
The 🚀bug has been fixed and incorporated into the master. The development of the new features mentioned above has also been completed. Repeat the above process to merge the code, as shown below:
Because the branch for bug fixing and the branch for developing new features are all based on the master, after bug fixing, the master is not the original master, and it runs a lot of way to the front. You need to manually resolve the ✋ conflict and commit the code.
2.1- Push to remote:
1. Create a remote repository (here I’m using Gitee:Gitee.com/)
It needs to be globalgit
To restrict:
git config --global user.name "bulala"
git config --global user.email "[email protected]"
Copy the code
2. Push code to remote repository:
Git remote add origin / / https://gitee.com/rapsai/gitlearn.git to far called orign warehouse, Git push -u origin master git push -u origin masterCopy the code
3. Clone warehouse code:
- Clone code includes branch ha, clone code can branch operation
git clone https://gitee.com/rapsai/gitlearn.git
Copy the code
4. Pull the company code at home:
🌵 Developed code in the company:
Git checkout dev 2 Git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master 3 git merge master Git add. Git commit -m"XXX function"
git push origin dev
Copy the code
🌵 Continue to develop in the company:
1. Switch to the dev branch git checkout dev 2. Git pull Origin dev 3 Git add. Git commit -m"Xx popover completed"
git push origin dev
Copy the code
🌵 development completed to online:
Git checkout master git merge dev git push origin master 2 Git checkout dev git merge master git push origin devCopy the code
Git instruction diagram: