1. Any branch can be created locally. If you do not push it to the server git, the contents of the server will not be affected.
2. Use git push as follows:
Git push file: // home/hebo/work/testgit/Master
In this way, only the master branch is pushed to the server.
However, if you want to push other local maintenance branches to the server, you must
Git push file: // home/hebo/work/testgit/local_hebo, local branches must also exist
Question:
1. Why can I use git branch to view branches in a self-built git project, but the branch I used git branch to view in an android project is empty?
2. Why can't I build a branch like remote/umg/froyo, while android can
3. Repo init-u git: // android.intel.com/manifest-B froyo-M prod-BB indicates what?
Use the above example to do the following experiment:
1. Git init m2doc
Create an empty m2doc library and use ll to view the experiment. You can see that there is only one. Git directory.
2. Git remote add HB/home/hebo/work/test_hebo_git/m2doc. Git/
Add a tag for a remote repository and use this tag for management. You can use git remote show to view the tag for a remote HB repository, and use git remote show HB to view the tag, generate the following information. At this time, the show command will communicate with the remote repository through the network:
* Remote HB
Fetch URL:/home/hebo/work/test_hebo_git/m2doc. Git/
Push URL:/home/hebo/work/test_hebo_git/m2doc. Git/
Head branch: Master
Remote branches:
Local_sub_local new (next fetch will store in remotes/Hb)
Master new (next fetch will store in remotes/Hb)
This information indicates the captured remote address, head branch, which is equivalent to master branch. local_sub_local branch exists remotely and master branch exists. If git clone is used, an original label is automatically created.
3. Git fetch HB
Synchronization of data from a remote warehouse to a local warehouse creates a mirror that is exactly the same as that of a remote warehouse.
Remote: counting objects: 686, done.
Remote: compressing objects: 100% (663/663), done.
Grouping objects: 100% (686/686), 1020.29 kib, done.
Remote: Total 686 (delta 132), reused 0 (delta 0)
Resolving deltas: 100% (132/132), done.
From/home/hebo/work/test_hebo_git/m2doc
* [New branch] local_sub_local-> HB/local_sub_local
* [New branch] Master-> HB/Master
In this case, the data is actually retrieved from the remote warehouse and synchronized to the local warehouse. We can see that local_sub_local corresponds to the remote hebo/local_sub_local, and the master corresponds to the remote HB/Master
4. Use git checkout HB/local_sub_local
The following message is displayed: checking out 'hb/local_sub_local '.
You are in 'detached head' state. You can look around, make experimental
Changes and commit them, and you can discard any commits you make in this
State without impacting any branches by using Ming another checkout.
If you want to create a new branch to retain commits you create, you may
Do so (now or later) by using-B with the checkout command again. Example:
Git checkout-B new_branch_name
Indicates that the current status is "detached head", which may be viewed in this status. For the experiment, use git Branch
The following message is displayed: * (no branch), indicating that the local branch has not been determined.
5. Git checkout local_sub_local
Pull a local_sub_local branch from the local database and use git Branch
* Local_sub_local
You can see the Branch currently in local_sub_local.
6. Git checkout master
Pull a master branch from the local machine and use git Branch
Local_sub_local
* Master
You can see that the current master branch has two local branches: local_sub_local and master.
7. Git checkout HB/Master
Pull an empty branch from the local device. This branch is temporary and local modifications cannot be saved.
Use git checkout HB/master again, and then use git Branch
* (No Branch)
Local_sub_local
Master
You can see that the current dual is in the remote no branch.
8. Use of git diff
Git diff is a powerful tool for comparing local and local caches, remote branches, and tags labels.
Example: git diff -- stat remotes/umg/froyo-stable remotes/umg/froyo-prod-bb
You can use git diff sha1 sha2 path to compare different files in a directory, or use git diff -- relative to compare different files in the current directory.
You can use git diff in a work tree for comparison, or you can use git diff branch_name1 branch_name2 in a repository for comparison. The comparison is based on
In essence, the repository is based on the hash value. If the local repository is not updated, it cannot be compared to the local database creation, but the remote database creation has some updated nodes.
Thus, the remote/umg/branch_name corresponds to a local repository, and a network connection is initiated only when git remote show orginal is used, you can see whether updates are available remotely. If there is any update, it will be displayed (next fetch will store in remotes/umg)
9. For information with the same name as the local directory
You can use git diff master test3 --
Add a -- after test3 to indicate that this is a branch, not a path.
10. Git rev-Parse naming is an underlying command. It is useful to translate some titles into object names occasionally.
$ Git rev-Parse Origin
E05db0fd4f31dde7005f075a84f96b360d05984b
You can obtain the hash value of the branch and tag.
11. Use of git diff
Common command formats for git to compare differences between files of different versions:
- Git diffFilenameView the updates to a file that has not been saved
- Git diff-cachedFilenameView the differences between a saved file and the last submitted version.
- Git diff ffd98b291e0caa6c33575c1ef1_eae661ce40c9 b8e7b00c02b95b320f14b625663fdecf2d63e74c view the differences between two versions
- Git diff ffd98b291e0caa6c33575c1ef1_eae661ce40c9
12. Git checkout
After git branch new_branch, git checkout new_branch is equivalent to creating a branch from the current local branch. The content in the work tree is consistent with the current branch. If you want to update the content, from the remote branch merge to the current branch, git merge origin/branch_name. If new_branch name is the same as that in remote, you can see
Local branch configured for 'git pull ':
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
If the current new_branch name is inconsistent with that in remote, you can see the following during git remote show origin:
Local branch configured for 'git pull ':
Master merges with remote master
Local ref configured for 'git push ':
Master pushes to master (up to date)
We can see that the new branch cannot be directly pushed to the server at this time.
If you use git checkout-track origin/branch_name, this command is equivalent to git checkout-B branch_name origin/branch_name,
Local branches configured for 'git pull ':
HB merges with remote HB
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
If git checkout-B new_bracn origin/branch_name, it is displayed that another_branch will not be directly pushed to the server.
Local branches configured for 'git pull ':
Another_branch merges with remote HB
HB merges with remote HB
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
13. Git show-ref
List references in a local repository browse references in the local repository.
14. Git VaR
Show a git logical variable and-l parameters show local logical variables.
15. Use the following method to get the data from fetch, which is the same as that captured by the repo,
Git init bionic
CD bionic/
Git remote add HB git: // shumg001.sh.intel.com/a/aosp/platform/bionic.git
Git fetch HB
Output result:
Emote: generating pack...
Remote: done counting 6707 objects.
Remote: deltifying 6707 objects...
Remote: 100% (6707/6707) done
Remote: Total 6707 (delta 4616), reused 6446 (delta 4420)
Grouping objects: 100% (6707/6707), 2.55 MIB | 156 kib/s, done.
Resolving deltas: 100% (4616/4616), done.
From git: // shumg001.sh.intel.com/a/aosp/platform/bionic
......
* [New branch] froyo-integ-mfld-> HB/froyo-integ-mfld
* [New branch] froyo-integ-pr1-> HB/froyo-integ-pr1
* [New branch] froyo-integ-Sr-> HB/froyo-integ-SR
* [New branch] froyo-prod-BB-> HB/froyo-prod-bb
......
* [New tag] android-sdk-2.0.1_r1-> android-sdk-2.0.1_r1
* [New tag] android-sdk-2.1_r1-> android-sdk-2.1_r1
* [New tag] android-sdk-tools_r2-> android-sdk-tools_r2
Remote: generating pack...
Remote: done counting 5 objects.
Remote: deltifying 5 objects...
Remote: 100% (5/5) done
Remote: Total 5 (delta 2), reused 5 (delta 2)
Unpacking objects: 100% (5/5), done.
From git: // shumg001.sh.intel.com/a/aosp/platform/bionic
* [New tag] android-2.0_r1-> android-2.0_r1
* [New tag] android-sdk-2.0_r1-> android-sdk-2.0_r1
* [New tag] android-sdk-tools_r3-> android-sdk-tools_r3
* [New tag] android-sdk-tools_r4-> android-sdk-tools_r4
* [New tag] android-sdk-tools_r5-> android-sdk-tools_r5
In the refs directory, the remote/HB/branch name and tags/Tag name are generated. The content of the head file points to ref: refs/heads/master.
You can use git checkout -- track HB/froyo-prod-BB to locally generate a local branch with the same name as the branch froyo-prod-BB, use git checkout-B my_topic HB/froyo-prod-BB to generate a local branch,
You can use git remote show branch to view its relevance with the remote branch, as shown below:
Local branches configured for 'git pull ':
Froyo-prod-BB merges with remote froyo-prod-bb
My_topic merges with remote froyo-prod-bb
Local ref configured for 'git push ':
Froyo-prod-BB pushes to Froyo-prod-BB (up to date)
Note: The cause of this problem is that a local git project is copied and then cloned based on this project, because there is only my_topic locally, only one my_topic branch is cloned, and the remote branch of the server is no longer cloned. The clone is relative. for cloning, there is only one parent, it has nothing to do with his father's father.
16. Use git cat-file and git LS-tree to check which commit corresponds to the current file in the checkout.
If you want to use git checkout head ^. to roll back the current directory to a previous version, and then want to know which version is returned, you can try the following method:
I. view the Sha value of commit through git log
Ii. Find the corresponding tree, parent's SHA-ID through git cat-file commit SHA-ID
Iii. view the SHA-ID with git ls-tree to find the Blob SHA-ID for this file under the current tree
Iv. You can use git LS-files-s to save the SHA-ID of files under the current path, so that you can know which file is checkout
However, if you need to roll back the file, you can use branch to roll back the version and then compare it.
For example, if you want to return to the previous several changes, you can git checkout-B my_topic_xxmonth_xxday_xxhour_xxminute sha_id. In this way, you can verify on this branch and then use git log to know the status of the log.
Original translated from: http://blog.csdn.net/gracioushe/article/details/6129891
1. Any branch can be created locally. If you do not push it to the server git, the contents of the server will not be affected.
2. Use git push as follows:
Git push file: // home/hebo/work/testgit/Master
In this way, only the master branch is pushed to the server.
However, if you want to push other local maintenance branches to the server, you must
Git push file: // home/hebo/work/testgit/local_hebo, local branches must also exist
Question:
1. Why can I use git branch to view branches in a self-built git project, but the branch I used git branch to view in an android project is empty?
2. Why can't I build a branch like remote/umg/froyo, while android can
3. Repo init-u git: // android.intel.com/manifest-B froyo-M prod-BB indicates what?
Use the above example to do the following experiment:
1. Git init m2doc
Create an empty m2doc library and use ll to view the experiment. You can see that there is only one. Git directory.
2. Git remote add HB/home/hebo/work/test_hebo_git/m2doc. Git/
Add a tag for a remote repository and use this tag for management. You can use git remote show to view the tag for a remote HB repository, and use git remote show HB to view the tag, generate the following information. At this time, the show command will communicate with the remote repository through the network:
* Remote HB
Fetch URL:/home/hebo/work/test_hebo_git/m2doc. Git/
Push URL:/home/hebo/work/test_hebo_git/m2doc. Git/
Head branch: Master
Remote branches:
Local_sub_local new (next fetch will store in remotes/Hb)
Master new (next fetch will store in remotes/Hb)
This information indicates the captured remote address, head branch, which is equivalent to master branch. local_sub_local branch exists remotely and master branch exists. If git clone is used, an original label is automatically created.
3. Git fetch HB
Synchronization of data from a remote warehouse to a local warehouse creates a mirror that is exactly the same as that of a remote warehouse.
Remote: counting objects: 686, done.
Remote: compressing objects: 100% (663/663), done.
Grouping objects: 100% (686/686), 1020.29 kib, done.
Remote: Total 686 (delta 132), reused 0 (delta 0)
Resolving deltas: 100% (132/132), done.
From/home/hebo/work/test_hebo_git/m2doc
* [New branch] local_sub_local-> HB/local_sub_local
* [New branch] Master-> HB/Master
In this case, the data is actually retrieved from the remote warehouse and synchronized to the local warehouse. We can see that local_sub_local corresponds to the remote hebo/local_sub_local, and the master corresponds to the remote HB/Master
4. Use git checkout HB/local_sub_local
The following message is displayed: checking out 'hb/local_sub_local '.
You are in 'detached head' state. You can look around, make experimental
Changes and commit them, and you can discard any commits you make in this
State without impacting any branches by using Ming another checkout.
If you want to create a new branch to retain commits you create, you may
Do so (now or later) by using-B with the checkout command again. Example:
Git checkout-B new_branch_name
Indicates that the current status is "detached head", which may be viewed in this status. For the experiment, use git Branch
The following message is displayed: * (no branch), indicating that the local branch has not been determined.
5. Git checkout local_sub_local
Pull a local_sub_local branch from the local database and use git Branch
* Local_sub_local
You can see the Branch currently in local_sub_local.
6. Git checkout master
Pull a master branch from the local machine and use git Branch
Local_sub_local
* Master
You can see that the current master branch has two local branches: local_sub_local and master.
7. Git checkout HB/Master
Pull an empty branch from the local device. This branch is temporary and local modifications cannot be saved.
Use git checkout HB/master again, and then use git Branch
* (No Branch)
Local_sub_local
Master
You can see that the current dual is in the remote no branch.
8. Use of git diff
Git diff is a powerful tool for comparing local and local caches, remote branches, and tags labels.
Example: git diff -- stat remotes/umg/froyo-stable remotes/umg/froyo-prod-bb
You can use git diff sha1 sha2 path to compare different files in a directory, or use git diff -- relative to compare different files in the current directory.
You can use git diff in a work tree for comparison, or you can use git diff branch_name1 branch_name2 in a repository for comparison. The comparison is based on
In essence, the repository is based on the hash value. If the local repository is not updated, it cannot be compared to the local database creation, but the remote database creation has some updated nodes.
Thus, the remote/umg/branch_name corresponds to a local repository, and a network connection is initiated only when git remote show orginal is used, you can see whether updates are available remotely. If there is any update, it will be displayed (next fetch will store in remotes/umg)
9. For information with the same name as the local directory
You can use git diff master test3 --
Add a -- after test3 to indicate that this is a branch, not a path.
10. Git rev-Parse naming is an underlying command. It is useful to translate some titles into object names occasionally.
$ Git rev-Parse Origin
E05db0fd4f31dde7005f075a84f96b360d05984b
You can obtain the hash value of the branch and tag.
11. Use of git diff
Common command formats for git to compare differences between files of different versions:
- Git diffFilenameView the updates to a file that has not been saved
- Git diff-cachedFilenameView the differences between a saved file and the last submitted version.
- Git diff ffd98b291e0caa6c33575c1ef1_eae661ce40c9 b8e7b00c02b95b320f14b625663fdecf2d63e74c view the differences between two versions
- Git diff ffd98b291e0caa6c33575c1ef1_eae661ce40c9
12. Git checkout
After git branch new_branch, git checkout new_branch is equivalent to creating a branch from the current local branch. The content in the work tree is consistent with the current branch. If you want to update the content, from the remote branch merge to the current branch, git merge origin/branch_name. If new_branch name is the same as that in remote, you can see
Local branch configured for 'git pull ':
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
If the current new_branch name is inconsistent with that in remote, you can see the following during git remote show origin:
Local branch configured for 'git pull ':
Master merges with remote master
Local ref configured for 'git push ':
Master pushes to master (up to date)
We can see that the new branch cannot be directly pushed to the server at this time.
If you use git checkout-track origin/branch_name, this command is equivalent to git checkout-B branch_name origin/branch_name,
Local branches configured for 'git pull ':
HB merges with remote HB
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
If git checkout-B new_bracn origin/branch_name, it is displayed that another_branch will not be directly pushed to the server.
Local branches configured for 'git pull ':
Another_branch merges with remote HB
HB merges with remote HB
Master merges with remote master
Local refs configured for 'git push ':
HB pushes to HB (up to date)
Master pushes to master (up to date)
13. Git show-ref
List references in a local repository browse references in the local repository.
14. Git VaR
Show a git logical variable and-l parameters show local logical variables.
15. Use the following method to get the data from fetch, which is the same as that captured by the repo,
Git init bionic
CD bionic/
Git remote add HB git: // shumg001.sh.intel.com/a/aosp/platform/bionic.git
Git fetch HB
Output result:
Emote: generating pack...
Remote: done counting 6707 objects.
Remote: deltifying 6707 objects...
Remote: 100% (6707/6707) done
Remote: Total 6707 (delta 4616), reused 6446 (delta 4420)
Grouping objects: 100% (6707/6707), 2.55 MIB | 156 kib/s, done.
Resolving deltas: 100% (4616/4616), done.
From git: // shumg001.sh.intel.com/a/aosp/platform/bionic
......
* [New branch] froyo-integ-mfld-> HB/froyo-integ-mfld
* [New branch] froyo-integ-pr1-> HB/froyo-integ-pr1
* [New branch] froyo-integ-Sr-> HB/froyo-integ-SR
* [New branch] froyo-prod-BB-> HB/froyo-prod-bb
......
* [New tag] android-sdk-2.0.1_r1-> android-sdk-2.0.1_r1
* [New tag] android-sdk-2.1_r1-> android-sdk-2.1_r1
* [New tag] android-sdk-tools_r2-> android-sdk-tools_r2
Remote: generating pack...
Remote: done counting 5 objects.
Remote: deltifying 5 objects...
Remote: 100% (5/5) done
Remote: Total 5 (delta 2), reused 5 (delta 2)
Unpacking objects: 100% (5/5), done.
From git: // shumg001.sh.intel.com/a/aosp/platform/bionic
* [New tag] android-2.0_r1-> android-2.0_r1
* [New tag] android-sdk-2.0_r1-> android-sdk-2.0_r1
* [New tag] android-sdk-tools_r3-> android-sdk-tools_r3
* [New tag] android-sdk-tools_r4-> android-sdk-tools_r4
* [New tag] android-sdk-tools_r5-> android-sdk-tools_r5
In the refs directory, the remote/HB/branch name and tags/Tag name are generated. The content of the head file points to ref: refs/heads/master.
You can use git checkout -- track HB/froyo-prod-BB to locally generate a local branch with the same name as the branch froyo-prod-BB, use git checkout-B my_topic HB/froyo-prod-BB to generate a local branch,
You can use git remote show branch to view its relevance with the remote branch, as shown below:
Local branches configured for 'git pull ':
Froyo-prod-BB merges with remote froyo-prod-bb
My_topic merges with remote froyo-prod-bb
Local ref configured for 'git push ':
Froyo-prod-BB pushes to Froyo-prod-BB (up to date)
Note: The cause of this problem is that a local git project is copied and then cloned based on this project, because there is only my_topic locally, only one my_topic branch is cloned, and the remote branch of the server is no longer cloned. The clone is relative. for cloning, there is only one parent, it has nothing to do with his father's father.
16. Use git cat-file and git LS-tree to check which commit corresponds to the current file in the checkout.
If you want to use git checkout head ^. to roll back the current directory to a previous version, and then want to know which version is returned, you can try the following method:
I. view the Sha value of commit through git log
Ii. Find the corresponding tree, parent's SHA-ID through git cat-file commit SHA-ID
Iii. view the SHA-ID with git ls-tree to find the Blob SHA-ID for this file under the current tree
Iv. You can use git LS-files-s to save the SHA-ID of files under the current path, so that you can know which file is checkout
However, if you need to roll back the file, you can use branch to roll back the version and then compare it.
For example, if you want to return to the previous several changes, you can git checkout-B my_topic_xxmonth_xxday_xxhour_xxminute sha_id. In this way, you can verify on this branch and then use git log to know the status of the log.
Original translated from: http://blog.csdn.net/gracioushe/article/details/6129891