Basic methods of using GIT distributed version management tools

Source: Internet
Author: User
Tags using git version control system

First, Git introduction

Previous Linux kernel code hosted in BitKeeper, this is commercial, but free for Linux community use;

Linux community has a person to try to crack BitKeeper, was bitkeeper found no longer free access to the use, so Linus spent two weeks to develop a distributed version control system, is git;

In fact, git function and SVN is similar, but SVN is centralized management, git is distributed management;

Centralized management: Must have a service side, the code warehouse is on the server side, the client (PC) need to synchronize the code from the servers to their own computers, the development of the end to push to the service side, this architecture relies on the network, the transmission is relatively slow;

Distributed: There can be no server, all personal computers can have a complete code base, code updates, push, branch, merge can be done on their own computer. It also supports multi-person collaboration, but requires a common git server as a support.

Second, install git

1. CentOS:

Yum-y Install Epel-release

Yum-y Install git

2, on Ubuntu

sudo apt-get install git

3. Install Msysgit on Windows

https://git-for-windows.github.io/

After the installation is complete, you will also need to set the user name and mailbox

git config--global user.name "Fansik"

git config--global user.email "[Email protected]"

When the user name and mailbox are set, the. gitconfig file is generated in the user's home directory

Iii. Create a repository and push files

Mkdir/home/gitroot

Cd/home/gitroot

Initialize, let/home/gitroot programming git can manage the warehouse

Git init

After initialization, a. Git directory is generated in the/home/gitroot directory

Add a file

echo "Fansik\nnimei" > Fansik.java

Adding changed files to the code warehouse (using Git diff after join will not see the difference, but using git status to see the files that are staged and show the changes)

git add Fansik.java

To revoke a submission:

git reset HEAD Fansik.java

If the file is modified but you want to revert to the content in the repository, you can use:

# git checkout--Fansik.java

To submit the staging file to the repository:

Git commit-m "Add new Fansik.java"

iv. Change of version

After changing the Fansik.java file multiple times and making add and commit operations, you can view the change history through git log.

Git log shows all logged operations that commit to a git repository

git log--pretty=oneline Each modification is displayed as a line

With git log, you can view all the versions that were submitted in the past, so you can specify a fallback version based on this log

git reset--hard dee6 This logo version, logo can be abbreviated (minimum 4 bits)

When you return to this version, the top version of Git log is not displayed, if you first return to the first line that version can use Git reflog display all versions

v. Deletion of files

Delete Files First

RM-RF 2.txt

Delete a staging file

git rm 2.txt

Delete Files in a warehouse

git commit-m "Delete 2.txt"

Basic methods of using GIT distributed version management tools

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.