Git common commands Summary, collation

Source: Internet
Author: User
Tags diff git commands

As a result of a Web project to go to the turntable network (http://www.quzhuanpan.com), and a few friends to do, considering the code hosting, teamwork, so in-depth study of git, the following are some common git commands, share to everyone, I hope you like.

1. Create an empty repository (admin, normal user ignored)
Git--bare init
Or:
Mkdir-p Src.git
CD Src.git
git--bare init--shared


2. Organize the source code (admin use, ignore by normal user)
(1) Delete the compilation generated files and folders in the source code
(2) Delete the. git folder and the. gitignore file in the source code
Find. -type d-name ". Git" |xargs rm-rf
Find. -type f-name ". Gitignore" |xargs RM-RF
Find. -type f-name ". Gitattributes" |xargs RM-RF


Recursively finds files containing the specified string under a directory
grep ' string '. -R--color


3. Configure git (important, each user needs to use)
git config--global color.ui true to enable Git to also display colors
git config--global user.name "Nick.wang" set git user name
git config--global user.email [email protected] set git mailbox


4. View history (important, often used by each user)
git log--name-status
Displays a list of log and modified files for each modification


git log--graph
Show version Map


5. View the differences
Git diff
Show the difference between workspace and staging area


git diff--cached
git diff--staged
Show the differences between staging area and git libraries


6. Ignore files that have been tracked
Files that have been tracked, and then used. Gitignore Ignore will not work, at this point you can use the following command:
git update-index--assume-unchanged file_name


To undo the operation, use the following command:
git update-index--no-assume-unchanged file_name


7. Merging the last two submissions
git commit--amend-m "XXXX"
Consolidate this submission into a single commit


8. Remote operation
git remote-v show Remote repository
git remote add NAME URL


Example: Git remote add mt6575-ics2 [email protected]:~/repo/lily5-ics2.git
If you want to push the branch branch_a in the local repository to the remote branch Branch_b on the MT6575-ICS2
OK:
git push mt6575-ics2 Branch_a:branch_b
If you want to pull all branches of MT6575-ICS2 to the local
OK:
git fetch MT6575-ICS2
Then switch the workspace to MT6575-ICS2 's Branch_b
git checkout--track mt6575-ics2/branch_b


If the B code base is clone from a code base, then the name of a library is automatically: Origin
Can: Git pull orgin master, or git push orgin master


To push a local branch to a remote branch
Git push Origin Local_branch_name:remote_branch_name


Show Remote Branch:
Git branch-r


Show all branches (include remote branch and local branch)
Git branch-a


Get Remote branch:
git checkout-b local branch name Remote branch name
Or
git checkout--track origin/r8625qsoskqly_3020
The above two commands have the same effect


9. Branching operations
Show local Branch
Git branch


Create a branch from the current location
Git branch <branch_name>


Create a branch from a specified location
Git branch <branch_name> <commit_id>


Rename a branch that you have already created
git branch-m <old_branch_name> <new_branch_name>


Show Remote Branch
Git branch-r


Show local branch and remote branch
Git branch-a


Take the remote repository's branch branch_a locally, and automatically create a local branch with the name Branch_a
git checkout--track origin/branch_a
Note: Origin can be replaced with an alias from another remote repository
For example:

If the user works in a 8705c repository, the remote repository for 8703c is aliased:


git remote add 8703C [email protected]:~/repo/8703c-ap.git

Then, you can get any branch of 8703c by using the alias 8703C in the 8705c version of the repository.


git fetch 8703C//sync 8703c to 8705c version Library


Git branch-a//Display all branch information for 8703c and 8705c


git chekcout--track 8703c/branch_a
Pull the remote branch of 8703C to the local repository of 8705c,
and automatically creates a local branch with the same name, and then switches to this branch


10. Marking tags
git tag-a moba-msm8x25q-3050-ap-v0.0-m "xxx"
git tag-s v1.x-m "xxx"


11. Version Fallback
git reset--hard commit_id completely back to the specified version, including the repository and workspace
git checkout commit_id


12. Save Work status
Git stash "The comment of current working state"//Save changes to the workspace and then restore the workspace's code to the status of the latest commit
git stash apply//revert to the above state


You can also cache multiple times, the system will save the cache in the queue, with the following command to see the saved cache list
git stash List
You can use any one of the following commands
git stash apply [email protected]{1}//1 can be changed to other numbers as needed


13. Fallback the repository on the server
git reset--hard <commit_id>


Git push Origin HEAD--force


14. command to download AP code from Codeaurora:
Repo init-u git://codeaurora.org/platform/manifest.git-b release-m LNX. La.3.2.1.4-00610-8x26.0.xml--repo-url=git://codeaurora.org/tools/repo.git


Patch-related operations
Compares the current branch to a specified branch to generate patches for different commits
git format-patch-m <local Branch name>

After switching to the target branch, apply a patch
git am xxxx.patch


You can extract patches between any two commits on the same branch
git format-patch <commit_id old>. <commit_id new>


Note: <commit_id old> represents a commit that is older than the current one, <commit_id new> represents a commit that is closer to the current time, with two between two commits. Connect.

Git is a very convenient tool, reasonable use, inefficient.
Other interested friends can also look at our GIF online authoring tool: http://sosogif.com/make_online.jsp

Git common commands Summary, collation

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.