Git's learning Notes (i)--initial knowledge of git and repository management

Source: Internet
Author: User
Tags commit install homebrew parent directory svn version control system
Introduction

Git is currently the world's most advanced distributed version control system, is the management of Linux source version control system, is currently used to manage the Android source code version control system. one, the installation of Git 1, installed under the Linux platform

First, we can enter gitto check if Git is already installed, and if it does not install it will prompt you, you can enter the command by typing:sudo apt-get install git

$ git The program
' git ' was currently not installed. You can install it by typing:
sudo apt-get install git

On the other hand, Git is already installed, it will show, and in the last line we can see thatgit is almost a smart tip
2, two kinds of installation mode of MAC platform

One is to install homebrew, and then install Git through homebrew, refer to Homebrew's documentation: http://brew.sh/
The second method is simpler (recommended), with Git installed directly from the AppStore installation Xcode,xcode, but not installed by default, you need to run Xcode, choose the Menu "Xcode", "Preferences", and in the pop-up window find " Downloads ", select" Command line Tools "and click" Install "to complete the installation. 3. Installation under Window platform

When you want to use a lot of Linux/unix tools under Windows, you need to cygwin such a simulation environment, GIT is the same. Cygwin installation and configuration are more complex, I also have a wooden configuration. The use of cattle people to the simulation environment and git are packaged up, so-called Windows version of Git, just need to download a separate EXE installer, the other do not install anything, and then the default options installed. After installation, find Git Bash in the Start menu and pop up a command-line window that shows that the GIT installation was successful. Second, configure Git 2.1 Common Configuration commands

git config for a git repository default current directory is a git repository, suppose we have a warehouse called Git_demo, it modifies the configuration saved in the Git_demo/.git/config file, if the current directory is not a valid git repository, Error when executing some commands

git config–global for a user, that is, as long as this user operation of any git repository, then this configuration will take effect, this configuration is stored in the ~/.gitconfig, what kind of configuration needs to be placed in the user's profile, One of the most important information in Git is the submitter's personal information .

$ git config--global user.name "Your name"
$ git config--global user.email "youremail@example.com"
sudo git config–system for a system, because it is for the entire system, so you have to use sudo, for all users of a system, where the configuration is effective for all users, what kind of configuration needs to be put here, such as we are executing git The commit will pop up a default editor, typically Vim, which, as the system administrator, can set vim as the default editor for all users
$sudo git config--system core.editor vim

You can also configure additional user.xxx properties. Because Git is a distributed version control system, it is easier to track later when collaborating. 2.2 using alias to reset git command aliases

For example, entering Git ci is equivalent to entering Git commit-s, as input git st is equivalent to entering GIT status

$sudo git config--global alias.st status
$sudo git config--global alias.ci "commit-s"
$sudo git config--global alias.co checkout
$sudo git config--global alias.br branch

Where the –global parameter is not required, you can also use –system instead. 2.3 Turn on the color display of the git command

$git config--global color.ui true
Iii. Creating and managing a local repository

The so-called Repository, also known as the Warehouse, English name repository, can be easily understood as a directory (that is, hidden . Git folder), All of the files in this directory's parent directory (the so-called workspace) can be managed by git, and each file can be tracked to be traced at any time by modifying or deleting it. 1. Create an empty local repository

Create an empty repository just two, create an empty directory ( in Windows system, to avoid all kinds of inexplicable problems, make sure that all directory names and parent directories do not contain Chinese ), and then init (git init)

ubuntu2@ubuntu:/media/s2/share$ mkdir codebanks//Create a directory that is the workspace
ubuntu2@ubuntu:/media/s2/share$ cd codebanks// Enter into the directory
ubuntu2@ubuntu:/media/s2/share/codebanks$ pwd//display the current command
/media/s2/share/codebanks

After completing the first step, just create an empty directory, not a so-called repository, so you have to initialize, execute git init command after the directory will be more than a hidden. Git folder (this directory is git to manage the repository, do not manually modify the files in this directory, otherwise serious consequences), it means that the empty version of the repository has been created.

ubuntu2@ubuntu:/media/s2/share/codebanks$ git init
Initialized empty git repository in/media/s2/share/codebanks/ . git/

After Git 1.6.5 or later, we can enter the directory name directly after the GIT init can also complete the initialization

ubuntu2@ubuntu:/media/s2/share$ git init codebanks

2. Change the existing directory to a local repository that can be managed by Git

Of course, we don't always have to create a git repository in an empty directory, and it's also possible to select an existing directory. You only need to cut to the path of the directory where you can execute git init . 3. Add files to the Git local repository

Generally divided into two main steps, first, using the command git add filename, (can be reused multiple times, add multiple files); second, use the command git commit-m "submitted content description" submission. But if committing to the remote repository submission process is a little more complicated to avoid conflicts.

Git submits code to repository general process
  git Status View current repository status
  git diff view specific changes
  git add-u Add all code to staging area
  git show Modified serial number (can view specific changes to file contents (already submitted))
  git log-4--pretty=oneline--stat view four commit history and a line showing
  git commit-m "Your brief description of this submission" Submit

The repository can only add files directly to the repository, so when we add files to an empty repository, the first step is to copy the files to the repository and then add, commit.

when not added after copying to repository

after add

commit git commit-m "commit description"

when Ps:commit, be sure to add the-m parameter: Otherwise git log will be reported Fatal:bad default revision ' HEAD ' because it will think that the repository is not committed in the inside, so it will report this error. 4. Submit a new version

If we modify the Aw08.txt file externally before add , the view repository git status will prompt

So unlike SVN, each commit has to add and commit.
5. Go back to a version of the history record

Unlike SVN, Git automatically generates a commit ID that is not a one-off after every successful commit ... Incrementing the number, instead of using SHA1 to calculate a very large number, in hexadecimal means that each commit Id uniquely corresponds to a version , with HEAD for the current version, that is, the latest commit c042e4b66 ... CEAC5, the previous version is head^, the previous version is head^^, then the hundreds of versions. Of course not to write hundreds ^, but the first 100 are written **head~**100. 5.1 using git reset–hard to see the version number pointed to by the current head pointer

5.2 using git reset–hard head^ back to the previous version of the current version

5.3 Return to the corresponding version via git reset–hard commit Id

5.4 using git reflog to view historical operations records

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.