Linux under Git operations (iii)--branch management and tag __linux

Source: Internet
Author: User
Tags aliases commit git mergetool
This article commands:
The configuration display color is: git config--global color.ui true

to set aliases to commands: Git config--global alias.co checkout

View remote repositories: Git remote-v To

create a remote warehouse branch: git checkout-b dev origin/dev

Create a branch: Git branch <name>

View branch: Git branch

Toggle branch: Git Checkout <name>

Create + Toggle branch: Git checkout-b <name>

Merge a branch to the current branch: git merge <name>

Delete branch: git branch-d <name>

View branch merge diagram: git log--graph

---
staging now: Git stash

list stash:git Stash list

Do not delete the contents of the stash after recovery: git stash apply

restore after deleting content in stash: git stash pop     

---
disable merge for fast forward mode: git merge--no-ff-m "Merge with No-ff" Dev
One, branch:

With a branch, we can create a branch that belongs to you. Others can not see, but also continue to work in the original branch, and you are working on your own branch, want to submit to submit, until the development is completed, and then once again merged into the original Main branch (master), so that it is safe and does not affect the work of others. 1, create the branch:

$ git checkout-b dev
Switched to a new branch ' Dev '

You can then view your newly created branch:
$ git Branch

After the split is created, Dev obtains all the contents of the current version of Master Main branch.


* Represents the current branch, master is the primary branch. 2, switch, Merge branch:

Now I have created a file ABC in the dev branch and submitted it to the local warehouse Dev branch, which will only be in the Dev branch and will not be submitted in master, which is the equivalent of master for the release version, and each branch is the directory where the user works.

git checkout dev: switch to Dev Branch

$ git merge dev: merge the dev branch into the current (branch that is the primary directory branch)

After merging, the home directory will receive Dev's modifications to the file directory, and the ABC file can be found in the master directory. 3, delete the branch:

$ git branch-d dev: Remove Dev Branch

The- D argument can only delete branches after merging, and if the branch is not merged, you need to force the deletion with-D:
$ git branch-d Dev: forcibly deleting unincorporated branches 4, resolving conflicts:

Suppose you made a change to the file, and master also made changes to the file. When you switch to master, it will also remind you to submit a few more times than master:

Your Branch is ahead of ' Origin/master ' by N commit.

Then you start merging, because you make different changes to the file, so there is a conflict when submitting it. Then, we need to solve them manually.

When you view hello, we will find that:

Git uses <<<<<<<,=======,>>>>>>> to mark the contents of different branches.

<<<<<<< mark conflicts begin with the contents of the current branch.

The head points to the commit of the current branch terminal.

After =======,>>>>>>> is the code on another branch that you want to merge over.

The dev after >>>>>>> is the name of the branch.

For a simple merge, edit them manually, and then remove the tags, and finally add and commit as usual.

If the conflict is too complex, you need to use a graphical interface:
Git mergetool

git log--graph: View branch merge diagram. 5, Branch management strategy:

When merging a branch, if possible, Git uses the Fast forward mode, but in this mode, after the branch is removed, the branch information is discarded and the mode is disabled with –NO-FF.

Git merge--no-ff-m "merge with No-ff" Dev 6, bug branch:

When you're halfway there, there's a bug that needs to be solved, but you don't have the job done yet, but you don't want to commit, Git also provides a stash feature that allows you to "store" the current work site and continue working after you resume the site later:

$ git stash       //Staging now work
Saved working directory and index state WIP in dev:6224937 add merge head
4937 Add Merge

$ git status      //workspace is clean # on
branch Dev No to
commit (working directory cleaning)

First determine which branch to fix the bug on, assuming you need to fix it on the master branch, create a temporary branch from master:

$ git checkout master
switched to branch ' master '
Your branch was ahead of ' Origin/master ' by 6 commits.

$ git checkout-b issue-101     //Set up temporary branch to modify bug
switched to a new branch ' issue-101 '

After modifying the bug, you can continue the work just now. List with git stash list

$ git stash list
stash@{0}: WIP on dev:6224937 Add merge

How to resume work:
Git stash apply: Do not delete stash content after recovery
Git stash pop: delete stash content after recovery

Of course, we can also repeatedly stash, restore time, first with Git stash list view, and then restore the specified stash, with the command:
$ git stash apply stash@{0} II, label management:

SVN is more convenient than git in the version fallback, git version back so troublesome, we certainly have to find a way to solve, so there is a label.
1, create the label:

First, under the branch where you want to create a label, the label defaults to the current version when the label is created.
git tag v1.0: creating Labels

git tag: View tags

Label Previous submissions:

View Historical Submission ID Number: git log--pretty=oneline--abbrev-commit (can be written directly as Git log)

For example, to label a string func this submission, its corresponding commit ID is 241bc49, type the command: $ git tag v0.9 6224937

Create a label with a description, specify the label name with-A, and-m to specify the descriptive text:
$ git tag-a v0.1-m "version 0.1 released" 3628164 2, Operation label:

$ git tag-d v0.1: deleting labels
$ GIT push Origin v1.0: push content to remote
$ GIT push origin--tags: a one-time push all has not been pushed to the remote local label:

If the label has been pushed to the remote, remove the remote label to make it a bit cumbersome to remove it from the local area first:

$ git tag-d v0.9
Deleted tag ' v0.9 ' (was 6224937)

Then, remove from the remote. The Delete command is also push, but the format is as follows:

$ git push origin:refs/tags/v0.9

git reset--hard v0.2: Rollback to v0.2 version 3, config alias:

git config--global color.ui true: Configure display colors

Because words like checkout are too long, so we want to configure aliases.

Set the checkout alias Co,commit to CI:

git config--global alias.co checkout
git config--global alias.ci commit    

–global is a global variable and is applicable to the entire computer. Later I just need to write Git co on it, no need to write checkout.

The git configuration files for each warehouse are placed in the. git/config file

This article refers to: Liaoche Teacher Official Blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.