Mom doesn't have to worry about me using git anymore.

Source: Internet
Author: User
Tags diff tagname using git git clone
Mom doesn't have to worry about me using git anymore.

Dec, 2014 git.

Git is favored for its flexibility, speed, and off-line work, and the following step-by-step summary of Git's basic commands and common operations. Install Msysgit

Download Address: Msysgit, configure the system environment variables after installation, open git bash, use the graphical tools git GUI as little as possible, and recommend the command line.

You can operate git locally, or you can manipulate git at the remote server warehouse, such as GitHub, so you need to configure the SSH key, please check the official documentation Generating-ssh-keys GIT operation 1, checkout warehouse (clone warehouse)

Local clones:

$ git clone/path/to/repository

Remote cloning:

$ git clone <server>

SSH method (recommended), for example:

$ git clone git@github.com:hcy2367/hcy2367.github.io.git

Https method, for example:

$ git clone https://github.com/hcy2367/hcy2367.github.io.git
2, create a new warehouse
$ git init
3. Add workspace (working dir) new or changed files to registers (index or stage)
$ git Add <filename> | --all | -A

Git workspace, registers, head area (which can be understood as the latest version of the local Repository Master branch) Diagram:

4. Delete the added or altered files from registers

$ git rm--cached <filename> | *
5. View current warehouse Status

It is best to look at some state information that is currently submitted before and after the add, commit operation, and to prevent leaks from being added and submitting incorrectly

$ git status
6, view and compare the modified content
$ git diff <filename>
7, view the historical version of the submission (add Parameters: –pretty=oneline, for the output of a small amount of information)
$ git log
8. Submit to current Branch master head area
$ git commit-m ' Code submission information '
9, version fallback

Head represents the current version, the previous version is head^, the first version is head^^, up to 100 versions of head~100, such as back to the previous version, the command is as follows:

$ git reset--hard head^

Where the –hard parameter represents the modification of the undo workspace and registers, and fallback to the specified history version, you can use the following command:

$ git reset--hard 20038

Where 20038 is the first five-bit ID number (original: 20038c521d4e81aca8ec8bca9f05d50ebb4fb835) of the submitted version, you can use the following command when viewing:

$ git Reflog
10. Undo Modification

Discard changes to the workspace, files that have been added to registers are not affected, note: No less-parameters, commands are as follows:

$ git checkout-<filename> | *

Undo the registers changes and put them back in the workspace, as follows:

$ git reset Head <filename> | *
11, delete the file

Delete and then commit to the head area, if mistakenly deleted files, you can revert to the latest version of the file.

$ git rm <filename>
12, push to the remote warehouse
$ git push-u Origin Master | <branch>

The-u parameter indicates that the local master branch and the remote Master branch are associated when the initial push is made;

If you have not cloned an existing repository and want to connect your local warehouse to a remote server, you can use the following command to add:

$ git Remote add Origin <server>

For example, you will be able to push your changes to the server you are adding:

$ git Remote add Origin git@github.com:hcy2367/hcy2367.github.io.git
13. Branch

To create a branch:

$ git checkout-b <branch>

Switch back to Main branch:

$ git Checkout Master

List all branches:

$ git Branch

Merge the specified branch to the current branch (by default, the Fast Forward method):

$ git Merge <branch>

Normal mode merge (disables Fast forward because history submissions are not visible after merging):

$ git merge--no-ff-m "merge with No-ff" <branch>

To delete a branch:

$ git branch-d <branch>

Discarding a branch that has not been merged can be forcibly removed by using the following command:

$ git branch-d <branch>

Push to remote warehouse:

$ GIT push origin <branch>
14. Update and merge

To view remote information:

$ git remote-v

Get the latest version from the remote to the local warehouse and automatically merge to the local branch:

$ Git pull Origin Master

Get latest version from remote to local warehouse, do not automatically merge to local branch:

$ git fetch

Update the code to a different branch before merging the branches, and then commit to the remote warehouse after the local merge, and when there is a conflict, use the $ git diff or $ git status command to see the differences in the branch, manually resolve, and then execute $ git add <filename> command to mark them as merged successfully. View submission History graphic Information:

$ git log--graph--pretty=oneline--abbrev-commit
15, the label (can be understood as a version of the library snapshot)

To create a label:

$ git tag <tagname>

You can use commands such as the following to find the history-submitted ID number:

$ git log--pretty=oneline--abbrev-commit

Tag again:

$ git Tag v1.0 6224937

You can also create a label with a description, specify a label name with-A, and-m to specify the descriptive text:

$ git tag-a v1.1-m "version 1.1 released" 3628164

View Tags:

$ git tag

To view the label information:

$ git Show v1.0

To delete a local label:

$ git tag-d v1.1

Push label to Remote:

$ GIT push origin <tagname>

Push all not-pushed labels at once:

$ GIT push origin--tags

Delete Remote tags (delete local, then delete the corresponding remote tag):

$ git tag-d v1.1
$ git push origin:refs/tags/v1.1
16, discard all your local changes and submissions, you can go to the server to obtain the latest version and your local landlord branch point to it:
$ GIT fetch origin
$ git reset--hard origin/master
17. Remove all files that are not tracked (usually with parameter-df,-d to include directory, F to force Purge)
$ git clean [options]
18, the work of the collaboration of many people first, you can try to use $ GIT push origin <branch> push their own changes; if the push fails, because the remote branch is newer than your local one, you need to use $ git pull to try to merge, and if the merge conflicts, resolve the conflict, and submit locally; no conflict or resolve conflict, then use $ GIT push origin <branch> push to succeed; if git pull prompts "No tracking information", Then the link relationship between the local branch and the remote branch is not created, with the command $ git branch--set-upstream <branch> origin/<branch> resolved. 19, Git Work flow chart

Having said so much, a work drawing may be more understandable:

Summarize

Mastering the above commands makes it easy to use GIT to manage projects and participate in team development. When you appreciate Git's extraordinary and lovely place, you may never want to use SVN to manage your code anymore, and mom doesn't have to worry about how I use git, so you can China materialia to GitHub, Gitcafe, Gitlab of the sky, for the open source of the ecological circle to contribute their own strength. Whether it is fork,star,clone, or pull request, always try to the unknown world. [Blog shifted] = " http://hcy2367.github.io/

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.