Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Branch management, remote branch management, label management, git aliases

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Branch management

# cd / data/gitroot# git branch / / View the branch of the current warehouse * master / / there is only one line here, which is the current branch of the * number # git branch aming / / create the branch, named aming# git branch aming* master

/ / * the number is still in master, which means it is still on the maser branch.

# git checkout aming / / git checkout, switch the branch to the branch 'aming'# git branch / / then view the branch, * the number has reached aming * aming master# ls / / the files in the current branch and master are the same 1.txt# vim 2.txt / / write a new file under the aming branch # git add. # git commit-m "add 2.txt" / / to get the changes into the version repository, all you need is git commit. [root@MRX gitroot] # ls1.txt 2.txt [root@MRX gitroot] # git checkout master switch to branch 'master' [root@MRX gitroot] # ls / / switch to 1.txt without 2.txt under master

Branches are isolated from each other, and the operation files between branches and branches are not affected by each other.

Branch merging

The aming branch made changes, but the master branch did not. Now if you want the two branches to change the same, you can use merge branches. Merge the aming branch into the master branch, and the two branches are consistent.

# git checkout master / / before merging branches, switch to the target branch # git merge aming / / merge the changes in the aming branch into the master.

If both the master branch and the aming branch have edited the 2.txt, a conflict will be prompted when the merge occurs, and the conflict needs to be resolved before the merge can proceed.

The way to resolve the conflict is to edit the 2.txt under the master branch and change it to the content of 2.txt in the aming branch. Then submit the 2.txt and merge the aming branch.

But there is a problem, what if the master branch changes what we want? You can edit the 2.txt content, change it to what you want, and then submit. Switch to the aming branch, then merge the master branch into the aming branch (merge backwards). The principle of merging branches is to merge the newest branches into the old ones. In other words, the name of the branch followed by merge must be the latest branch. If you master this principle, you will not make mistakes.

# git branch aming* master [root@MRX gitroot] # vim 2.txt / / 2.txt under the master branch added several lines uipaduviadpeuqpvan4989496hgiasdiahusdf# git add 2.txt# git commit-m "ch 2.txt" # git checkout aming# vim 2.txt / / aming branch 2.txt deleted several lines uipaduviadpeuqpvan# git add 2.txt# git commit-m "ch 2.txt" # git checkout master# git merge aming automatic merge 2.txt conflict (content): merge conflict 2.txt automatic merge failed Fix the conflict and then submit the result of the amendment. # cat 2.txt / / at this point, different parts of the 2.txt will be automatically marked. Uipaduviadpeuqpvan > aming [root@MRX gitroot] # vim 2.txt uipaduviadpeuqpvan# git checkout aming2.txt: needs mergeerror: you need to resolve the current index conflict / / here is another problem. When you merge and have conflicts, you cannot switch to another branch. So try to avoid merge conflicts # git add 2.txt# git commit-m "ch 2.txt" # git checkout aming switch to branch 'aming'# git merge aming / / the content of the two branches is consistent, and then the merge will not make any change. Already up-to-date.

# git branch-d aming / / Delete branches. If you are under the current branch, you cannot delete the current branch and switch to another branch.

If the branch is not merged, it will be prompted before deletion, then do not merge and force deletion:

# git branch-D aming

II. Remote branch management

Principles for using branches

For the application of branches, it is recommended that the following principles be used:

Master branch is very important, online release code with this branch, usually we do not develop code on this branch.

Create a dev branch dedicated to development, and merge the dev branch into master only before it is published online

Developers should branch into personal branches based on dev, develop code in personal branches (on their own pc), and then merge into dev branches.

The command for dev branches to merge bob branches is:

# git checkout dev / / switch to the dev branch first, and then # git merge bob

Remote branch

New branches created locally will not be visible to others if they are not pushed remotely.

Common sense: git clone can only clone one branch of master.

Create a new file linux.doc and a new branch dev.

After the branch is created successfully, click again, and you can see that the check box is in front of the dev, where you can choose to change the branch.

Go back to the command line to look at the branch, clone the project first, and you can find that there is only one master branch.

Looking at the remote branch git ls-remote origin, you can see all the branches.

# git ls-remote origin45337b0d65a36760796a0f3a45e3f90e1d38ed4e HEAD41b9784a6f7aeecb1d485e956b10232b5114592a refs/heads/dev45337b0d65a36760796a0f3a45e3f90e1d38ed4e refs/heads/master

For git push branches, there are two cases.

When the local branch is consistent with the remote branch, git push pushes all changes from the local branch to the remote, such as master and dev.

If you want to push only one branch, use git push origin branch-name.

When there are more local branches than remote branches, the default git push only pushes the same local and remote branches. When you want to push the extra local branches to the remote, use git push origin branch-name. If the push fails, use git pull to grab the remote new submission first.

When git clone, only master branches are cloned by default. If you want to clone all branches, you need to create them manually. Create the corresponding branches locally and use git checkout-b branch-name origin/branch-name. The names of local and remote branches should be the same. The two branch-name here refer to the name of the remote branch.

The # git checkout-b dev origin/dev branch dev is set to track the remote branch dev from origin. After switching to a new branch 'dev'# vim 4.txt# git add 4.txt# git commit-m "add 4.txt" # git push0b51fcb..43fd64d dev-> dev / / git push, the last line can see that it was pushed from dev to dev. If you refresh it remotely, you can see that 4.txt appears under the dev branch, but master does not.

III. Label management

Tags are similar to the snapshot function in that you can label a version library to record the status of a time library. You can also return to this state at any time.

Git checkout master first switches to the master branch, and later tagging is also done for the master branch. Git tag v1.0 tag master v1.0 git show v1.0 View tag information git tag View all tags under the current branch tag is tagged for commit, so you can label tag,v1.0 for historical commit. Git log-- pretty=oneline-- abbrev-commit / / look at the historical commit first, and the following option refers to the abbreviated commit. Git tag v0.9 46d3c1a / / tag the historical commit git tag-a v0.1-m "first tag" 2ec587f / / you can describe the tag # git show v0.1tag v0.1Tagger: aming Date: Thu Sep 19 11:06:29 2019 + 0800first tag / / for the tag information, you can see the description commit 2ec587ff6e9e0e4c67aefb84e02b2b73693d633eAuthor: aming Date: Sun Sep 8 14:59:15 2019 + 0800first commitdiff-- git a/README.md b/README.mdnew file mode 100644index 0000000 .6f0cbdemuri-/ dev/null+++ bplink README.mdink @-0recol 0 + 1 @ + # apelearn

Git tag-d v0.8 / / remove tags

The previous operations are all on the client side and have not yet been pushed to the remote server.

Check the tags method on the remote, in the option to switch branches:

Git push origin v1.0 / / push the specified tag to the remote

Git push-- tag origin / / push all tags

If a tag is deleted locally and you want to delete it remotely, you need to do this:

Git tag v0.8-d / / Delete local tags

Git push origin: refs/tags/v0.8 / / Delete remote tags

IV. Git alias

The command git commit can be expressed as an alias, and using an alias can improve our productivity. Format: git config-- global alias. Alias command name gitconfig-- global alias.ci commit gitconfig-- global alias.co checkout gitconfig-- global alias.br branch these aliases are configured in the / root/.gitconfig file and can be changed within the file. Check git aliases using the command git config-- list | grep alias query log Tips: # git config-- global alias.lg "log-- color-- graph-- pretty=format:'%Cred%h%Creset -% C (yellow)% d%Creset% s% Cgreen (% cr)% C (bold blue)% Creset'-abbrev-commit" # git lg / / you can see the user, time, description and tag. * 45337b0-(HEAD, tag: v1.0, origin/master, origin/HEAD, master) add 3.txt (6 days ago) * 41b9784-Create linux.doc (7 days ago) * d816b47-add 1.txt (13 days ago) * 0c8b170-add 2.txt (13 days ago) * 2ec587f-first commit (13 days ago) cancel alias git config-global-unset alias.br

Summary:

Branch management

Git branch View Branch

Git checkout master switching branch

Git merge aming merges changes in the aming branch into master

Git branch-d aming delete branch

Git branch-D aming forcefully deletes branches

Remote branch management

Git ls-remote origin View remote Branch

Git push origin branch-name pushes a single branch

Create a branch corresponding to the remote branch locally, using git checkout-b branch-name origin/branch-name

Label management

Git tag v1.0 label the master branch v1.0

Git show v1.0 View tag Information

Git tag view all tags

Git log-- pretty=oneline-- abbrev-commit commit for viewing history

Git tag-a v1.0-m "first tag" 2ec587f describes the tag

Git tag-d v0.8 remove tags

Git push origin v1.0 pushes the specified tag to the remote

Git push-- tag origin pushes all tags

Git tag v0.8-d remove local tags

Git push origin: refs/tags/v0.8 removes remote tags

Git alias

Git config-- global alias. Alias command name

Git config-- list | grep alias to view aliases

Git config-global-unset alias.br

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report