In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
[root@localhost ~] # mkdir xgp [root@localhost ~] # cd xgp/ [root@localhost xgp] # git init initializes the empty Git version library at / root/xgp/.git/ [root@localhost xgp] # vim xgp.txt [root@localhost xgp] # cat xgp.txt 111master [root@localhost xgp] # git add xgp.txt [root@localhost xgp] # git commit-m "first submission from master Branch" [master (Root submission) b211b8e] first submission from master Branch 1 file changed 1 insertion (+) create mode 100644 xgp.txt
First, we create the dev branch, and then switch to the dev branch:
[root@localhost xgp] # git checkout-b dev
Switch to a new branch 'dev'
The git checkout command plus the-b parameter means create and switch, which is equivalent to the following two commands:
$git branch dev
$git checkout dev
Switched to branch 'dev'
Then, use the git branch command to view the current branch:
[root@localhost xgp] # git branch
Dev
Master
The git branch command lists all branches, and the current branch is preceded by a * sign.
Then we can commit normally on the dev branch, such as making a change to xgp.txt and adding a line:
[root@localhost xgp] # cat xgp.txt
111master
Added by Qqqqdve
Then submit:
[root@localhost xgp] # git add xgp.txt [root@localhost xgp] # git commit-m "first dev" [dev eac3426] first dev 1 file changed, 1 insertion (+)
Now that the work of the dev branch is complete, we can switch back to the master branch:
[root@localhost xgp] # git checkout master
Switch to branch 'master'
After switching back to the master branch, look at a xgp.txt file, and the content you just added is gone! Because that commit is on the dev branch, and the commit point of the master branch has not changed at this point:
[root@localhost xgp] # cat xgp.txt
111master
Now, let's merge the work of the dev branch into the master branch:
[root@localhost xgp] # git merge dev Update b211b8e..eac3426Fast-forward xgp.txt | 1 + 1 file changed, 1 insertion (+)
The git merge command is used to merge the specified branch into the current branch. After the merge, if you look at the contents of xgp.txt, you can see that it is exactly the same as the latest submission from the dev branch.
Noticing the Fast-forward information above, Git tells us that this merge is in "fast-forward mode", that is, pointing the master directly to the current submission of dev, so the merge is very fast.
Of course, not every merger can be Fast-forward, we will talk about other ways of merger later.
After the merge is complete, you can safely delete the dev branch:
Check it out
[root@localhost xgp] # git log commit eac342633a72b3590a019e4d758f4a60707acda2Author: admin Date: Thu Nov 14 09:18:47 2019 + 0800 first devcommit b211b8ef636e987166fb4a056fb778020f6518aeAuthor: admin Date: Thu Nov 14 09:12:11 2019 + 0800 Delete dev branch from master branch for the first time [root@localhost xgp] # git branch-d dev deleted branch dev (formerly eac3426). After deletion, check the branch and only the master branch is left: [root@localhost xgp] # git branch * master
Because creating, merging, and deleting branches is very fast, Git encourages you to use branches to accomplish a task, and then delete branches after merging, which is the same as directly in master
The effect is the same on the branch, but the process is safer.
Summary
Git encourages heavy use of branches:
View branches: git branch
Create a branch: git branch
Switch branches: git checkout
Create + switch branches: git checkout-b
Merge a branch into the current branch: git merge
Delete branch: git branch-d
Resolve the conflict
Nine out of ten things go wrong in life, and merging branches is often not plain sailing.
Prepare a new xgp branch and continue our new branch development:
[root@localhost xgp] # git checkout-b xgp switches to a new branch 'xgp' modifies the last line of xgp.txt Instead: [root@localhost xgp] # cat xgp.txt 111masterqqqqdve conflict is added to the xgp branch to submit: [root@localhost xgp] # git add xgp.txt [root@localhost xgp] # git commit-m "xgp conflict" [xgp 9a92c8f] xgp conflict 1 file changed 1 insertion (+) switch to master branch: [root@localhost xgp] # git checkout master switch to branch 'master' [root@localhost xgp] # cat xgp.txt 111masterQqqqdve change the last line of the xgp.txt file on the master branch to: [root@localhost xgp] # cat xgp.txt 111masterqqqqdvebug conflict add submission: [root@localhost xgp] # git add xgp.txt [root@localhost xgp] # git commit-m "1 submission conflict" [master 43f4ad7] 1 submission conflict 1 file changed 1 insertion (+)
Now, the master branch and the xgp branch each have new commits, which looks like this:
In this case, Git cannot perform a "quick merge" and can only try to merge their respective changes, but such a merge may be conflicting, so let's try it:
[root@localhost xgp] # git merge xgp
Automatically merge xgp.txt
Conflicts (content): merge conflicts with xgp.txt
Automatic merge failed, correct the conflict and then submit the result of the correction.
There was a conflict! Git tells us that there is a conflict in the xgp.txt file and that the conflict must be resolved manually before submitting. Git status can also tell us about conflicting files:
[root@localhost xgp] # git status # is located in the branch master# and you have paths that have not yet been merged. # (resolve conflicts and run "git commit") # # unmerged paths: # (use "git add..." Mark solution) # # bilateral modifications: xgp.txt# modifications have not been added to the submission (using "git add" and / or "git commit-a") We can directly view the contents of xgp.txt: [root@localhost xgp] # cat xgp.txt 111masterqqqqdve
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.