Android learning notes: One of the essential Android development tools, the command line creates the Git Library (Dean)

Source: Internet
Author: User
Tags file diff git commands

In the previous article, I briefly described the basic Git operations for a standard process! Now I try to build a git library and operate the file to analyze the usage of git commands! Use SSH to allow LAN students to access and push and clone!

The following tool kits must be installed:
Java code
Git Toolkit
Sudo apt-get install git-core
Git tool for a graphical operation interface
Sudo apt-get install gitk
LAN access.
Sudo apt-get install ssh


Note! Set up now!
Create a workspaces folder first
Java code
Deanye @ dean :~ $ Mkdir workspaces
Deanye @ dean :~ $ Cd workspaces


 


Use this folder as the version Library
Java code
Deanye @ dean :~ /Workspaces $ git init
Initialized empty Git repository in/home/deanye/workspaces/. git/


 
Java code
HEAD indicates the latest status.
A tag is a status tag.
SHA1 is the unique identifier of each submitted log.
Developers need to configure relevant information for the git repository so that the information will automatically
It is reflected in the logs of the git repository.

Git config user. name "your name"
Git config user. email yourname @ email_server
Git config core. editor vim
Git config core. paper "less-N"
Git config color. diff true
Git config alias. co checkout

 

In this way, an empty version library is created and a subdirectory named. git is created in the current directory. You can use ls-a to check the content and pay attention to the following three items:
* For a HEAD file, let's check its content:
$ Cat. git/HEAD
The contents of the HEAD should be as follows:
Ref: refs/heads/master
We can see that the content in the HEAD file only contains an index information, and this index will always point to the current development branch in your project.
* A subdirectory named objects contains all objects in your project. We do not need to know the content of these objects directly. We should be concerned with the project data stored in these objects.
Note
For details about the classification of git objects and descriptions of git object database, refer to [Discussion].
* A subdirectory called refs is used to store indexes pointing to objects.
Specifically, the subdirectory refs contains two subdirectories: heads and tags, just as their names mean: they store the indexes of the headers of different development branches, or the index of the tag you use to calibrate the version.
Note: The master is the default branch, which is why. git/HEAD points to the master when it is created, although it does not exist at present. Git will assume that you will start on the master and expand your future work, unless you create your own branch.
In addition, this is just a conventional habit. In fact, you can call your work branch any name, instead of having to have a master branch in the version library, although many git tools think that the master branch exists.
Now a git version library has been created, but it is empty and cannot do anything. The next step is how to implant data into the version library.

Create several files and folders
Java code
Deanye @ dean :~ /Workspaces $ mkdir text_a
Deanye @ dean :~ /Workspaces $ mkdir text_ B
Deanye @ dean :~ /Workspaces $ ls
Text_a text_ B
Deanye @ dean :~ /Workspaces $ echo "abc"> text_c
Deanye @ dean :~ /Workspaces $ echo "abcd"> text_d
Deanye @ dean :~ /Workspaces $ ls
Text_a text_ B text_c text_d
Deanye @ dean :~ /Workspaces $

 

 


View the current status
Java code
Deanye @ dean :~ /Workspaces $ git status

 

 
Java code
Diff:

After local development, developers can use git diff to view the changes.
In addition to comparing the changes made after development, git diff can also:

Git diff tag compares the differences between the tag and the HEAD.
Git diff tag file compares the differences between two files.
Git diff tag1.. tag2 compares the differences between two tags.
Git diff sha11.. SHA12 compares the differences between two commits.
Git diff tag1 tag2 file or
Git diff tag1: file tag2: file compares the differences between two tags of a file.


At this time, the status of the two text files added just now can be involved! The folder is empty and cannot be seen.

You can add a new text_c to the default branch master and view the status at the next time.
Java code
Deanye @ dean :~ /Workspaces $ git add text_c


 


Git add is actually a script command that calls git update-index, the git kernel command. Therefore, the above command is equivalent to the following command:
$ Git update-index -- add text_c
If you want to clear a file from the git directory tracking system, you can also use the git update-index Command. For example:
$ Git update-index -- force-remove text_c

You can also add all the changes in the current period (note that the changes are submitted to branch at this time)
Java code
Deanye @ dean :~ /Workspaces $ git add.

 

 


Use the git commit command to submit:
Java code
Deanye @ dean :~ /Workspaces $ git commit-m "first commit"

 

 


View Historical Changes
Java code
Deanye @ dean :~ /Workspaces $ git log

 

 

Java code
Log:

Git log file to view the changes to a file.
Git log-p to view logs and changes.
Git log tag1.. tag2: view the logs between two tags.
Git log-p tag1.. tag2 file to view the differences between two tags in a file.
Git log tag .. view the differences between tag and HEAD.


Modify two files and view the modified file diff
Java code
Deanye @ dean :~ /Workspaces $ git diff.


 


We can use the combined command git add and git commit again to submit our work to the version library.
Java code
Deanye @ dean :~ /Workspaces $ git add.
Deanye @ dean :~ /Workspaces $ git commit-m "second"


 

Or directly
Java code
Git commit-a-m "second"

Java code
Commit:

Git commit-a-e submits all modification files and calls vim to edit and submit logs.
Git reset HEAD ^ or
Git reset HEAD ~ 1. Cancel the last submission.
Git reset -- hard HEAD ^ undo the last commit and clear local modifications.
Git reset SHA1 returns to the submission status corresponding to SHA1.


Java code
Add/delete/ls:

Git add-a to add all files. Except for files in the. gitignore file.
Git rm file: delete a file from the git repository.
After git commit is added or deleted, it must be submitted.

Git ls-files-m Displays the modified files.
Git ls-files displays all files in the repository.


The above is the basic process of submission. The following is the focus and the essence of git.
Java code
Management Branch

View Current Branch
Java code
Deanye @ dean :~ /Workspaces $ git branch


 

Create a branch and move it to the Branch
Deanye @ dean :~ /Workspaces $ git checkout-B first

 


The git show-branch command shows the development status of each branch in the version library, and shows whether the content submitted each time has entered each branch.
Java code
Deanye @ dean :~ /Workspaces $ git show-branch


 

The hierarchy of branch is similar to that of tree
For the definition of the GIT version, see git help rev-parse

Use the git whatchanged command to check how the master branch develops.

Deanye @ dean :~ /Workspaces $ git checkout master

 

We can make changes on every different branch!
That is, there are a variety of different engineering environments!

Merge two branches: git merge
Java code
$ Git checkout master
$ Git merge-m "Merge" second

Merge the two branches in a simpler way. The following commands are equivalent to the preceding commands.
Java code
$ Git checkout master
$ Git pull. second

However, a merge conflict prompt is displayed in git: $ cat text_c and the conflict is resolved.
There are also more complex three-way merge and multi-content tree merge cases. For details, see git help read-tree and git help merge.

Reverse and recovery
Reverse and recovery: git reset
One of the important tasks of the project tracking tool is to enable us to reverse (Undo) and restore (Redo) a certain stage of work at any time.
The git reset command is prepared for such a task. It locates the head of the current work branch to any version previously submitted. It has three reset algorithm options.
Command Format:
Git reset [-- mixed | -- soft | -- hard] [<commit-ish>]
Command Options:
-- Mixed
It is only to reset the index position, without changing anything in your work tree (that is, all changes in the file will be retained, and they will not be marked as pending ), the system prompts that the content has not been updated. This is the default option.
-- Soft
We neither touch the index position nor change any content in the work tree. We only need to make the content a good one (and then become the real submitted content ). This option enables you to reset submitted items to the "Updated but not submitted" status. Just like you have run the git update-index Command, but haven't run the git commit command.
-- Hard
Switch the content and header indexes in the work tree to the specified version location, that is, all the trace content and work tree content after <commit-ish> will be lost. Therefore, this option should be used with caution unless you are very sure that you do not want to see any more.
An important technique-reverse commit and recovery
Java code
Git reset 44b8f4ca48673291ee6fa77f7c076c476a86f5f2 -- hard

Two types of labels
In git, there are two types of tags: "Light tag" and "signature tag ".
Technically, there is no difference between a "Light tag" and a branch, but we put it in the. git/refs/tags/directory instead of the heads directory. Therefore, it is easy to create a "Light tag.
$ Git-tag my-first-tag
If you want to tag a commit ID, although this command can be implemented through the right-click menu in gitk, this command is very helpful for practical application.
$ Git-tag mytag f0af6283824688f9d23426031734657661b54388
The "signature tag" is a real git object. It not only contains a pointer to the state you want to mark, but also a tag name and information, an optional PGP signature. You can use the-a or-s option to create a "signature tag ".
$ Git-tag-s <tag-name>

Access and operate this git repository on another computer
Java code
Deanye @ dean :~ $ Mkdir text
Deanye @ dean :~ $ Cd text
Deanye @ dean :~ /Text $ git clone ssh: /// deanye@10.100.13.126/home/deanye/workspaces
Initialized empty Git repository in/home/deanye/text/workspaces/. git/

 

 


Java code
Modify the file. If you need to submit the file, submit it to a branch of the git library.
Deanye @ dean :~ /Text/workspaces $ git branch
Obtain the current branch name
Deanye @ dean :~ /Text/workspaces $ git push ssh: // deanye@10.100.13.126/home/deanye/workspaces/$ REPO_PROJECT.git master: first

 

 

Java code
Git has four types of objects: blob, tree, commit, and tag.
Blob indicates a file, tree indicates a directory, commit indicates a submission history, and tag indicates a tag.
All four objects are represented by the SHA1 value. The git management repository is saved in the. git directory of the repository.
All required information.
Git ls-tree HEAD file displays the SHA1 value of the file in the HEAD.
Git cat-file-t SHA1 displays a type of SHA1.
Git cat-file type SHA1 displays the content of a SHA1. Type is one of blob, tree, commit, and tag.
Patch:
Git format-patch-1 generates the patch file corresponding to the last commit.
Git am <patch adds a patch file to the git repository.
Git am -- resolved if there is a conflict, execute it after resolving the conflict.
Git am -- skip discard the patch introduced by git am.
Conflict:
Git merge is used to merge two branches.
If there is a git diff conflict, use diff to view it directly,
The conflicting code is represented by <and >>>. Manually modify the conflict code.
Git update-index updates the modified File status.
Git commit-a-e submits the code modified to resolve the conflict.

Branch:
Git branch-a to view all branches.
Git branch new_branch creates a new branch.
Git branch-d branch: delete a branch.
Git checkout branch switches the current branch. The-f parameter can overwrite unsubmitted content.

Daemon:
Sometimes the update public code repository uses the patch method, or directly
Use git pull git: // ip/repo branch
To update everyone's code. To use git pull, you must
Run the machine that submitted the Code:
Git daemon -- verbose -- export-all -- enable = receive-pack -- base-path =/repo
Request-pull:
Git request-pull start url is used to generate statistics for this pull request.

Clean:

Git clean-dxf is used to clear untracked files.
Git clean-dnf can display the files to be deleted, but not those ignored by. gitignore.
Git reset -- hard HEAD is used to clear modifications to trace files.
 
Usage of constants
 
HEAD: indicates the latest commit.
MERGE_HEAD: if it is a commit generated by merge, it indicates another parent branch except the HEAD.
FETCH_HEAD: the object and ref information obtained using git-fetch are stored here, which is prepared for future git-merge.
ORIG_HEAD: Save the SHA-1 value of the parent node
HEAD ^: indicates the parent information of the HEAD.
HEAD ^: indicates the parent information of the HEAD parent.
HEAD ~ 4: indicates the four generations of HEAD information
HEAD ^ 1: indicates the information of the first parent of the HEAD.
HEAD ^ 2: indicates the information of the second parent of the HEAD.
COMMIT_EDITMSG: The submission information for the last commit.

Related Article

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.