Git version control system commonly use the command

Branch operation

1. List all local branches
git branch

2, lists all the remote branch
git branch -r

3, lists all the local branch and remote branch
git branch -a

4, create a new branch, but still remain in the current branch
git branch [branch-name]

For example, create a name for the dev branch:
git Branch dev

5, a new branch, and the branch switch to
git checkout -b [branch]

For example, to create a branch name dev and switch to the branch
git checkout -b dev

6, switch to the specified branch, and updates the workspace
git checkout [branch-name]

For example, switching to the branch dev
git checkout dev

7, merging branches to specify the current branch
git merge [branch]

For example, currently the master branch, dev branch into the master branch of the current up
git merge dev

8, delete branch
git branch -d [branch-name]

For example, delete the local dev branch
git branch -d dev

9, the local master branch to a remote server push
git push origin master

10, delete the remote branch
git push origin --delete <branchName>

11, clone designated branch to a local
git clone -b [branch branch name] [git Address]
Note: git clone is a clone of the master branch by default, you can use the -b parameter to specify a specific branch, in fact, not only supports the -b branch name, also supports tag names
git clone -b <branch-or- tag-or-commit> [git address]

For example, the dev delete remote branch
git push origin --delete dev

Otherwise, you can use this syntax, pushing an empty remote branch to branch, in fact, equivalent to delete remote branch:
git Branch -d <BRANCHNAME>
git the Push Origin: <BRANCHNAME>

Tag (tag) Operation

1, Tag List all, with the -l argument can wildcard filters Tag
Git Tag
example:
. "V1 *" Tag -l Git

2, light tag hit
git tag [tag name]

3, note tag
git tag -a [tag name] -m [message]

For example, the tag hit v1.0
git tag -a v1.0 -m 'v1.0 release '

4, post tagging
git tag -a [tag name] [ version]

5, to commit id assigned to tag
hit on the head unnecessary tag, may be in the previous versions, the version available previously submitted by the commit id log Git
Git tag -a [tag label] [commit id]
git tag -a [tag label] [commit id] -m "your message"
for example:
Git tag -a V1.1 9cbf3d0

6, delete the local Tag
git Tag -d [Tag]

For example, delete the local v1.0 tag
git tag -d v1.0

7, drop the remote Tag
git the Push Origin --delete Tag <Tagname>

There is another way to delete, pushing an empty tag to a remote
git tag -d <Tagname>
git the Push Origin: refs / Tags / <Tagname>

8, view the tag information
git show [tag]

9, submitted to the specified Tag
git the Push [Remote] [Tag]

For example, the label v1.0 pushed to the remote server
git push origin v1.0

10, to submit all Tag
git the Push [Remote] the --tags

10, gets the specified tag content
git clone -b [tag label] [Git Address]

Rename remote branch

In git rename remote branch, in fact, first delete the remote branch, and then rename the local branch resubmit a remote branch.

For example, the remote branch dev rename develop, as follows:
1. Remove the remote branch:
$ Git Push --delete Origin dev

2. Rename the local branch:
git Branch -m dev Develop

3. Push local branch:
git the Push Origin Develop

Version rollback

1, we can use the git log command to view history, and version rollback according to the actual situation, if the output too much information, you can add --pretty = oneline parameters
First, Git must know which version is the current version in Git in with HEAD represents the current version, which is the latest submitted 1094adb ... (note my submission ID and you certainly are not the same), the previous version is the HEAD ^, the previous version is the HEAD ^^, of course, up 100 100 ^ written version is easier to count, so write HEAD ~ 100
for example: fall back to the previous version, we can use the git reset command
git reset --hard HEAD ^
then we look at the current version of git log state library
git log

2, of course, we can also carry out the above mentioned id version rollback according to the commit
git the RESET --hard [the commit the above mentioned id]

summary

1, HEAD points to the current version is the version, therefore, Git allows us to shuttle between the versions of the history, use the command git reset --hard commit_id.

2, before the shuttle, you can view commit history with git log, in order to determine which version to fall back.

3. To return to the future, with git reflog view the command history in order to determine what you want to return to a future version.

Guess you like

Origin blog.51cto.com/13718210/2419996
Recommended