Repo and git usage Summary

Source: Internet
Author: User

1. Configure git Environment Variables

    git config –global user.name yourname    git config –global user.email yourname@gmail.com    git config –gloval core.editor vim

You can use cat ~ /. Gitconfig to check whether the configuration is correct.

2. Create a git Branch

For example, to create an origin/android-4.0.4_r1.2 branch, enter:

Git checkout-B android-4.0.4_r1.2 origin/android-4.0.4_r1.2git checkout aosp/xxxx // switch branch to aosp/xxx

3. add, delete, and modify files

Git add path/file1, path/file2... // Add and modify git checkout path/file // discard modifying git RM path/file // delete the file

Use git status to view the file modification status under the current Branch

4. Submit changes

Git commit // submit command. Enter the corresponding log to describe git commit -- Amend // submit command, which is different from the preceding command: This commit is essentially a job from the previous commit.

It is best to synchronize the code before submission:

git fetch aospgit rebase aosp/android-4.0.4_r1.2

Git fetch is equivalent to obtaining the latest version from a remote device to the local device, and does not automatically merge. To update and merge, run the following command:

git fetch origin mastergit log -p master..origin/mastergit merge origin/master

The above command First downloads the latest version from the master branch of the remote origin to the origin/Master branch, then compares the differences between the local master Branch and the origin/Master branch, and finally merges them.

The above process can be implemented in the following clearer ways:

git fetch origin master:tmpgit diff tmp git merge tmp

5. Push the Code submitted to the GIT Server

git push aosp HEAD:refs/for/android-4.0.4_r1.2


Others

1) how to view the branch version on the repo database:

git --git-dir=.repo/manifests/.git/ branch -a

2) How to discard local modification:

git remote updategit reset --hard <BRANCH>

For example:

git reset --hard origin/android-4.0.4_r1.2


3) how to view the modification history of a file

Enter the following command in the directory where the file to be switched is located:

Git log -- pretty = oneline file name

Then, the modification history is listed by row. A long string of numbers at the beginning of each row is the hash value generated by each submission. Then, you can view the specific modification records based on the hash value:

Git show Hash Value

4) how to view the changes to a submitted log

First, use git log to view the current commit, and compare the modified content using the GIT diff command based on the change-ID:

Git diff change-ID-1 change-ID-2 // compare the difference between two change-IDs. If the second change-ID is not specified, it is compared with the current one.

5) Update the code and merge local modifications.

git pull aosp android-4.2.2_r1

The above command is equivalent to git fetch and git merge. In actual use, git
Fetch is safer, because we can check the update before merge, and then decide whether to merge.

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.