Distributed version manager git basic operation guide

Source: Internet
Author: User
Tags git workflow using git

For any file, there are only three statuses in git: committed, modified, and staged ). Submitted indicates that the file has been securely stored in the local database. Modified indicates that a file has been modified, but it has not been submitted for storage, saved files are saved in the list to be saved when the file is submitted next time.

1. The basic Git workflow is as follows:

  1. Modify some files in the working directory

  2. Snapshot the modified files and save them to the temporary storage area.

  3. Submit the updates and dump the file snapshots saved in the temporary storage area to the GIT directory.

Ii. Install git

Yum install curl-devel expat-devel gettext-devel OpenSSL-devel zlib-devel-y

  1. Install from source code

    Tar zxf git-1.6.0.5.tar.gz

CD git-1.6.0.5
Make prefix =/usr/local
Make install

2. RPM package installation

Yum install Git-core-y

Iii. configuration before the first running of Git

Git configuration files include:/etc/gitconfig ,~ /. Gitconfig ,. git/config (in the working directory), each level of configuration will overwrite the same configuration on the upper layer, all. the configuration in git/config overwrites the variable with the same name in/etc/gitconfig.

1. User Information

Git config -- global user. Name "John Doe"

Git config -- global user. Email [email protected]

2. Editor

Git config -- global core. Editor vi

Git config -- list check the existing configuration information

-- Global option, read/write is/etc/gitconfig

-- System option, read and write is ~ /. Gitconfig

Iv. Basic git usage

Get the GIT repository of the project

1. initialize git init from the current directory

2. Clone eg: git clone git: // github.com/schacon/grit.git from the existing repository

All files under git's common operation working directory are in two statuses: tracked or not tracked. A tracked file is a file that has been incorporated into version control management. Other files are not tracked.

Basic operations

1. Git status determines which files are in what status

2. Git add filename to start tracking a new file or put the tracked file in the temporary storage area

3. Check the unsaved file updates in git diff.

Git diff -- cached: view the difference between the files that have been saved and the snapshot that was last submitted

4. Git commit-M "string" Submit the update only for files in the temporary storage area

Git commit-a-m "string" stores all tracked files and submits them together, skipping git add step 5.git RM filename to remove a file from the tracked file list

6. The GIT Rm -- cached filename file is deleted from the GIT repository, but it is still stored in the current working directory.

7. Move or rename the file in git MV file1 file2

8. view the submission history using git log

The GIT log-P-2-P option is displayed to show the differences in each submitted content.-2 indicates that only the last two updates are displayed.
Git log -- stat: How to quickly browse updates submitted by other collaborators
Git log -- pretty = oneline displays the submission history in a completely different and default format

Gitk is a tool for git's graphical query and submission history.

9. Git commit -- Amend Undo operation

Eg: git commit-M "Initial commit"
Git add File

The GIT commit -- Amend command finally gets a commit, and the second command fixes the content of the first commit.

10. Git reset head filename: cancels the temporary files. This command is a prompt command after git status.

11. Git checkout -- filename cancels file modification. This command is a prompt command after git status.

5. Use of remote warehouses

Git clone git: // github.com/schacon/ticgit.git

CD ticgit
1. Git remote list brief names of remote Libraries

Git remote-V displays the brief name and clone address of the remote database.

2. Git remote add Pb git: // github.com/paulboone/ticgit.git a new remote warehouse, which indicates a short name, and uses Git fetch PB to capture all the information that the local warehouse does not have.

3. git push origin master pushes the local master branch to the origin server. Only all clone servers have the write permission and no one else pushes data at the same time, this command will be executed as scheduled. If others push several updates, your operation will be rejected. You must capture their updates locally and go to your project, to push again

4. Git remote rename Pb Paul modifies the short name of a remote repository and changes PB to Paul

5. Remove git remote RM Paul from the remote Repository

This article is from the "Nyi tribe" blog. For more information, contact the author!

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.