3 Git branches - branch management

branch management

So far, you've learned how to create, merge, and delete branches. In addition, we also need to learn how to manage branches, and the management commands described below will be often used in routine work in the future.

git branch The command can not only create and delete branches, if no arguments are given, it will give a list of all current branches:

$ git branch
  iss53
* master
  testing

Pay attention to  master the character before the branch  * : it indicates the current branch. That is, if you commit an update now, the master branch will move forward as development progresses. To see information about the last commit object for each branch, run  git branch -v:

$ git branch -v
  iss53   93b412c fix javascript issue
* master  7a98805 Merge branch 'iss53'
  testing 782fd34 add scott to the author list in the readmes

To filter from this list the branches you have (or haven't) merged with the current branch, use the  --merged and  --no-merged options (Git 1.5.6+). For example, to  git branch --merged see which branches have been merged into the current branch.

$ git branch --merged
  iss53
* master

We've merged it before  iss53, so we'll see it here. In general, branches that are not in the list  * can usually be git branch -d used for deletion. The reason is simple, since the work they contain has been integrated into other branches, there is nothing to lose by deleting them.

You can also  git branch --no-merged view unmerged jobs with:

$ git branch --no-merged
  testing

It will show branches that haven't been merged in yet. Since these branches also contain work that has not yet been merged in, simply  git branch -d deleting the branch will prompt an error, as doing so will lose data:

$ git branch -d testing
error: The branch 'testing' is not fully merged.
If you are sure you want to delete it, run 'git branch -D testing'.

However, if you do want to delete the changes on that branch, you can force it with the uppercase delete option  -D , as given in the prompt above.

Information addressClick to open the link


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324830393&siteId=291194637