Something you don't know about Git

Source: Internet
Author: User

Last Friday, I used git reset -- HARD <commit-id> and lost my commit (poor). So I decided to re-learn git.

This article is not about git-based things, but about things you don't know or just use once or twice.

  1. Restore submission from reset -- HARD
    Just use the git reflog command.
    (Provided by Gittenberg)

  2. Diff
    If you want to see the differences between the two branches, you only need to do this: git diff branch1.. branch2.

  3. Use regular expressions to match submitted information and display
    Using the git show:/fixes command, you can find the most recent commit that contains the input string (fixes in this example) in the submit information.

  4. Restrict default behavior of git push
    If you run git push, the default behavior is to submit all the branches to the remote code library. This may cause many problems. If you do not want to do this, you can: git config -- global push. default tracking.
    Update: Git 2.0 removed this default behavior http://blog.nicoschuele.com/posts/git-2-0-changes-push-default-to-simple

  5. Switch to a branch rebase and merge to master
    You can do this: git rebase HEAD feature & git rebase HEAD @ {-2}

  6. Git save working status
    If your work is not completed yet, but you need to find it urgently, you can use git stash to save the changes and submit your urgent task, then use git stash pop to restore to the state you saved.

  7. Alias
    Are you still tired of entering checkout again and again? Now let's try: git config -- global alias. co checkout. You can use the git co master command to switch to the master.

  8. Rename a local branch
    Use: git branch-m old-name new-name you can easily rename a local branch.

  9. Search for author name
    You can use git log -- author = Matheus to search for a submission record of a specified author.

  10. Add parameters to git status
    Most people only use git status. However, you can pass in parameters to change the state display mode.
    Using git status-sb, you can get output similar to the following:

## master M Gemfile M Gemfile.lock M app/controllers/home_controller.rb M app/views/home/index.html.erb

Install Git on Ubuntu Server

Create a Git repository on the server (Ubuntu)

Git simple tutorial in Linux (taking Android as an example)

Git authoritative guide PDF

Git details: click here
Git: click here

This article permanently updates the link address:

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.