Use of Git

Source: Internet
Author: User

Prompt>Git init
Initialized empty git repository in/path/to/repo/. Git/
Prompt>
... Create file (s) for first commit...
Prompt>Git add
Prompt>Git commit-m'initial import'
Created initial commit bdebe5c: initial import.

1 files changed, 1 insertions (+), 0 deletions (-)

Create mode 100644 <some File>

Clone version Library
Prompt>Git clone <repository URL
Initialize repo/. Git
Initialized empty git repository in/work/<remote repository>/. Git/

Add contents in the directory to git Version Control
Prompt>CD/path/to/existing/directory
Prompt>Git init
Initialized empty git repository in/path/to/existing/directory/. Git
Prompt>Git add.
Prompt>Git commit-M "Initial import of some project"

Set the remote version library alias in the local version Library
... From within the repository directory...
Prompt>Git remote add <remote repository> <repository URL>

A.2 routine operations
Normal usage

This section lists the daily git operation commands, corresponding to Chapter 4th "add and submit: git basics" (page 41st ).

Add new files or save changes to existing files, and then submit
Prompt>Git add <some File>
Prompt>Git commit-M "<some message>"

Save some modifications to existing files
Note: [...] indicates an optional parameter.

Prompt>Git add-P [<some File> [<some File> [and so on]"
Select the text block to be submitted ......

Add a file in interactive mode
Prompt>Git add-I

Temporary modification of files already under git Version Control
Prompt>Git add-U [<some path> [<some path>]

Submit all changes to files under git version control # s"
Prompt>Git commit-M "<some message>"-;

Clear changes in the working directory tree
Prompt>Git checkout head <some File> [<some File>]

Cancel the temporary ID that has been saved but has not been submitted
Prompt>Git reset head <some File> [<some File>]

Fixed the problem in the last submission.

Modify related files and save the files ......
Prompt>Git commit-M "<some message>" -- Amend

Fix the problem in the previous submission and reuse the comments of the previous submission.
Prompt>Git commit-C head -- Amend


A.3 Branch
Branches
Branch is one of the strengths of git. This section describes the commands for branches. For details, see chapter 5th "understanding and using branches" (page 55th ).

List local branches
Prompt>Git Branch
List remote branches
Prompt>Git branch-R

List all branches
Prompt>Git branch-

Create a new branch based on the current Branch
Prompt>Git branch <new branch>

Detect another branch
Prompt>Git checkout <some branch>

Create a new branch based on the current branch and check the branch
Prompt>Git checkout-B <new branch

Create a new branch based on another starting point
You can create a new branch from any version in the version library. You can use an existing branch name, a submission name, or a label name to start the table.
Prompt>Git branch <new branch> <start point>

Create a new branch with the same name to overwrite the existing branch
Prompt>Git branch-F <some existing branch> [<start point>]

Move or rename a branch
Only when <New Branch> If the parameter does not exist
Prompt>Git checkout-M <existing branch name> <new branch name>

If <New Branch> If it already exists, overwrite it.
Prompt>Git checkout-M <existing branch name> <new branch name>

Merge another branch to the current Branch
Prompt>Git merge <some branch>

Merge but not submit
Prompt>Git merge -- no-commit <some branch>

Sort and merge and submit
Prompt>Git cherry-pick <commit Name>

Select and merge, but do not submit
Prompt>Git cherry-pick-n <commit Name>

Merge the content on one branch to another branch (one commit on the other)
Prompt>Git merge -- squash <some branch>

Delete Branch
Only when the branch to be deleted has been merged to the current Branch
Prompt>Git branch-D <branch to delete>

Whether or not the branch to be deleted has been merged to the current Branch
Prompt>Git branch-D <branch to delete>

A.4 history
History

These commands are used to display the historical information of the version library, including where the code was, who made what, modified content, and its statistics. For details, see chapter 6th "querying git history records" (page 71st ).
Show all history records
Prompt>Git log

Display version history and content differences between versions
Prompt>Git log-P

Show only the last submission
Prompt>Git log-1

Displays the last 20 submissions and content differences between versions.
Prompt>Git log-20-P

Show submissions in the last 6 hours
Prompt>Git log -- since = "6 hours"

Displays the submissions two days ago.
Prompt>Git log -- before = "2 days"

Displays the three commits earlier than the head (the ending point of the current branch ).
Prompt>Git log-1 Head
Or ......
Prompt>Git log-1 Head
Or ......
Prompt>Git log-1 Head

Show submission between two versions
The <start point> and <End Point> In the following command can be a submission name, branch name, tag name, or a combination of them.
Prompt>Git log <start point>... <End Point>

Display history. Each submission displays a line, including the first line for submitting comments.
Prompt>Git log -- pretty = oneline

Show Number of changed rows
Prompt>Git log -- stat

Display the name and status of the modified File
Prompt>Git log -- name-status

Display the differences between the current working directory tree and the temporary storage Interval
Prompt>Git diff

Display the differences between the temporary storage zone and version Library
Prompt>Git diff -- cached

Display the differences between the working directory tree and the version Library
Prompt>Git diff head

Displays the differences between a working directory tree and a version library for a specified submitted version.
<Start point> A submission name, branch name, or tag name.
Prompt>Git diff <start point>

Show differences between two versions in the version Library
Prompt>Git diff <start point> <End Point>

Display statistics on differences
Prompt>Git diff -- stat <start point> [<End Point>]

Shows the modifier and related submission information of each part of the file.
Prompt>Git blame <some File>

Shows the modifier and related submission information of each part of the file, including copying, pasting, and moving content in the file.
Prompt>Git blame-M <some File>

Displays the modifier and related submission information of each part of the file, including information on moving Content Between Files
Prompt>Git blame-C <some File>

Copy and paste information is displayed when history is displayed.
Prompt>Git log-C-p-1 <some point>

A.5 remote version Library
Remote Repositories

Developers share their work results and collaborate with each other through remote version libraries. This section describes the commands for these operations. For details, see chapter 7th "collaborate with remote version libraries" (page 91st ).

Clone a remote version Library
Prompt>Git clone <some repository>

Clone the remote version library, but only download the latest 200 submitted history records.
Prompt>Git clone -- depth 200 <some repository>

Set the remote version library alias in the local version Library
Prompt>Git remote add <remote repository> <repository URL>

Show remote branches
Prompt>Git branch-R

Create a local branch based on a remote Branch
Prompt>Git branch <new branch> <remote branch>

Create local branch based on remote tag
Prompt>Git branch <new branch> <remote tag>

The changes are obtained from the remote version library with the alias "Origin" but not merged to the local branch.
Prompt>Git fetch

Changes are obtained from any remote version Library but not merged to the local branch.
Prompt>Git fetch <remote repository>

Modify changes from any remote version library and merge the changes to the local branch currently Detected
Prompt>Git pull <remote repository>

Changes are obtained from the remote version library with the alias "Origin" and merged to the local branch currently detected.
Prompt>Git pull

Push modification changes from the local branch to the remote version Library
Prompt>Git push <remote repository> <local branch>: <remote branch>

Push the modification changes from the local branch to the branch with the same name in the remote version Library
Prompt>Git push <remote repository> <local branch>

Push modification changes from the new local branch to the remote version Library
Prompt>Git push <remote repository> <local branch>

Push the modification changes to the remote version library with the alias "origin ".
If a branch with the same name already exists in the remote version library, this command will push the local branch to the branch corresponding to the remote version library. If no branch with the same name exists in the remote version library, you must use git push <repository Name> <local branch>.
Prompt>Git push

Delete branch from remote version Library
Prompt>Git push <remote repository >:< remote branch>

Delete all branches that do not exist in the local version Library
Prompt>Git remote prune <remote repository>

Delete the abbreviation of a remote version library in the local version Library and the branches related to the remote version library.
Prompt>Git remote Rm <remote repository>

A.6 connect git and SVN
Git to SVN Bridge

Git can read data from the Subversion database and send local changes back to the Subversion database. This is one of the secrets that git distinguishes from other version control tools. For more information, see Chapter 10th "migrate to git" (page 131st ).
Clone all content of the SVN version Library
Prompt>Git SVN clone <SVN repository>

Clone the SVN version library with the standard structure
The following command is applicable to cloning standard structure SVN databases. That is to say, the trunk is named trunk, other branches are stored in the branches directory, and labels are stored in the tags directory.
Prompt>Git SVN clone-S <SVN repository>

Clone SVN version libraries with non-standard Structures
Prompt>Git SVN clone-T <trunk path> \
2]! W9 T7 X4 N) D; h # N (G4 I/h
-B <branch path> \
+ Q-E & | 5 K & N $ C1} 1 E
-T <tag path> \
7 V. | 9' & '9g, _ *

<SVN repository>
Clone a version of the SVN version library with a standard structure (for example, version 2321st)
Prompt>Git SVN clone-S-r 2321

Clone the SVN version library with the standard structure and add a prefix to the branch in SVN
Prompt>Git SVN clone-s -- prefix SVN/<SVN repository>

Obtain the updated content from the upstream SVN version library and change the basic branch in the local git version library accordingly.
Prompt>Git SVN rebase

Pushes the modification changes back to the upstream SVN version library.
Prompt>Git SVN dcommit

List all submissions that will be pushed to the upstream SVN Repository
Prompt>Git SVN dcommit-n

Display SVN history
Prompt>Git SVN log

Displays the svn modifier and related submission information for each part of the file.
Prompt>Git SVN blame <some File>

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.