Common git commands

Source: Internet
Author: User

Tag: git

I used tortoisegit for development in windows. I recently encountered a Linux project, so I started to use the GIT command and found that it was really nice to use it, the following are some frequently used commands that I need to summarize from my work.

  1. Create a repository git init

  2. Clone git clone URL

  3. Update code git pull

  4. Code submission

4.1 git add path/file name eg: git add APP/controller/cart_controller.rb

4.2 git commit-M "comment" eg: git commit-M "Modify bug001"

4.3 git push

5. Check the status

Check which code you have modified

Git status

6. view log

Git log

7. view the branch Graph

Git log -- Graph

8. Sometimes you may encounter a situation where the modification is complete and needs to be restored and used.

Git checkout -- path/file name

9. Check the submitted commit ID. This ID is still very useful. For example, if you want to view the specified log and restore it to the specified version, you need this ID.

Git reflog

10. view the specified log git log commit ID

Restore to the specified version of git reset -- hard commit ID

11. Sometimes you execute git add to the temporary storage area, but want to restore it, you need to use the following command

Git reset Head XXX. Rb

Now it is restored to the work zone. If you want to continue restoring it, use git checkout -- file name

12. Create a local branch and switch to the new branch.

Git checkout-B si_dev (my new Branch)

You can also take two steps.

Create git branch si_dev

Git checkout si_dev Switch

After si_dev modifies the code

Git add xxx

Git commit-M "XXXXX"

Switch to the original master branch, and then merge

Git checkout develop

Git merge si_dev

Git push

13. Delete used branches

Git branch-D si_dev

14. View submitted specified files

Git show commit ID file name

15. When a code conflict is submitted, either stash or stash is prompted .... (I showed up at push)

First, run git stash to restore the code.

Then git pull updates the code.

Then, bring the restored code pop to the master.

Git pop

16. Create a remote Branch


This article from the "monkey riding Tree" blog, please be sure to keep this source http://qihoushangshu.blog.51cto.com/7872138/1570557

Common git commands

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.