Basic configuration and usage examples for git under Linux systems

Source: Internet
Author: User
Tags commit comparison config diff root directory

git config profile

A. Git is already in your system, and you will do something to get your git environment to be customized. You only have to do these settings once; even if you upgrade, they will be bound to your environment. You can also change these settings again at any time by running commands.

Git has a tool called Git config, which allows you to get and set configuration variables that control all aspects of Git's appearance and operations. These variables can be stored in three different locations:

1./etc/gitconfig file: Contains values that apply to all users of the system and to all libraries. If you pass the parameter option '--system ' to git config, it will explicitly read and write this file.

2.~/.gitconfig files: specific to your users. You can make git read or write this particular file by passing the--global option.

3. config file located in git directory (i.e.. git/config): Regardless of what library you are currently using, specific points to that single library. Each level overrides the previous level's value. Therefore, the value in. Git/config overrides the same value in the/etc/gitconfig.

In Windows systems, Git looks for a. gitconfig file in the $home directory (for most people, under C:documents and Settings$user). It also looks for/etc/gitconfig, although it is relative to the Msys root directory. This could be anywhere you decide to install git when you run Setup in Windows.

Two. Your logo (Your identity)

2.1 The first thing to do when you install Git is to set your user name and e-mail address. This is very important because this information is used every time that git commits. It is permanently embedded in your submission:

The code is as follows:

$ git config--global user.name "John Doe"

$ git config--global user.email johndoe@example.com

Again, you just need to do this setup once. If you pass the--global option, because git will always use that information to handle everything you do in the system. If you want to use a different name or e-mail address in a particular project, you can run the command in the project without--global the option.

2.2 Your editor (Your Editor)

Now that your logo is set up, you can configure your default text editor, and Git will use the text editor when you need to enter some messages. By default, Git uses your system's default editor, which is usually either VI or VIM. If you want to use a different text editor, such as Emacs, you can do the following:

The code is as follows:

$ git config--global core.editor emacs

2.3 Your comparison tool (Your Diff Tool)

Another useful option you may need to configure is the default comparison tool, which is used to resolve conflicts during merging. For example, you want to use Vimdiff:

The code is as follows:

$ git config--global merge.tool vimdiff

Git can accept KDIFF3, Tkdiff, meld, Xxdiff, emerge, Vimdiff, Gvimdiff, Ecmerge, and Opendiff as effective merging tools. You can also set up a customized tool; see chapter 7th for more information on this.

2.4 Check your Setup (Checking Your settings)

If you want to check your settings, you can use the GIT config--list command to list all the settings that git can find at this point:

The code is as follows:

$ git config--list

User.name=scott Chacon

User.email=schacon@gmail.com

Color.status=auto

Color.branch=auto

Color.interactive=auto

Color.diff=auto

...

You may see a keyword appear multiple times, because git reads the same keyword from a different file (for example:/etc/gitconfig and ~/.gitconfig). In this case, Git uses the last value for each unique keyword.

You can also look at the current value of a particular keyword that git thinks of, using the following command git config {key}:

The code is as follows:

$ git config user.name

Scott Chacon

2.5 Get help (getting helps)

If you need help with Git, there are three ways to get the man page (manpage) Help for any git command:

The code is as follows:

$ git Help

$ git --help

$ mans git-

For example, you can run the following command to get Help on the hand album for config commands:

The code is as follows:

$ git help config

These commands are very friendly, because you can access them anywhere, even if they are not online. If the manual page and book are still insufficient and you need personal help, you can try using the #git or #github channel (irc.freenode.net) on the freenode ircserver. These channels are regularly maintained by hundreds of professionals who are very familiar with git and will be happy to help you.

2.6 Summary (Summary)

You should have a basic understanding of what git is and the difference between git and other cvcs you might use. You should also have a working git version of your personal identity in your system. It's time to learn some of Git's basics.

Git actually uses records

1. Git Submit code Error case Analysis

The code is as follows:

$ GIT push origin master

The code is as follows:

To Git@192.168.1.3:k6.git

! [Rejected] Master-> Master (Non-fast-forward)

Error:failed to push some refs to ' git@192.168.1.3:k6.git '

To prevent losing history, Non-fast-forward updates were rejected

Merge the remote changes before pushing again. The ' note about

Fast-forwards ' section of ' git push--help ' for details.

cbk@ycs:~/work/k6_130708/k6$ git fecth

git: ' Fecth ' is not a git command. "Git--help".

Git push error, because without first pull the latest code, the following actions are required:

The code is as follows:

$ GIT fetch origin

$ git Merge Origin/master

$ GIT push origin master

If you have not set up your user name and e-mail address after you install GIT, you will need to first perform the following:

The code is as follows:

$ git config--global user.name "CBK"

$ git config--global user.email cbk@ylf.com

This is very important because this information is used every time that git commits. It is permanently embedded in your submission:

Again, you just need to do this setup once. If you pass the--global option, because git will always use that information to handle everything you do in the system. If you want to use a different name or e-mail address in a particular project, you can run the command in the project without--global the option.

Specifically to this issue, if you do not set your user name and e-mail address, you will not be able to push the code correctly.

2, Git Tracking the submission history of a file

In tracking the Android code, it is sometimes found that a key file has been altered and needs to be tracked to see the records of all the commits to this key file in order to understand the reason and the process of the change:

The code is as follows:

git log-p "file name"

Displays the last commit commit for each line of this file to facilitate locating the commit:

The code is as follows:

Git blame "file name"

Display log detailed modification record:

Git show [Log_id_num], for example:

The code is as follows:

Git show 75704c8543b033619a80439ddb0fd69cc7cb172c

3, git initialization of git config

1). The following command modifies the/home/[username]/.gitconfig file, which means that the following configuration is visible only to users of each SSH, so everyone needs to do it.

The author's information is displayed in the log of the submitted code.

The code is as follows:

git config--global user.name [username]

git config--global user.email [email]

Turn on color display in git command

The code is as follows:

git config--global color.ui true

2). The following command modifies the/etc/gitconfig file, which is a global configuration, so admin can do it once.

Configure some common command alias for git

The code is as follows:

sudo git config--system alias.st status #git St

sudo git config--system alias.ci commit #git Commit

sudo git config--system alias.co checkout #git Co

sudo git config--system alias.br Branch #git Branch

3. You can also go to the working root directory and run git config-e so that only the. git/config files of the workspace are modified, but not for the time being.

The override order of the Git config file is 3) >1) >2).

4. Version fallback

The code is as follows:

git reset--hard commit_id

The code is as follows:

git checkout commit_id

The code is as follows:

Git clean–df commit_id

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.