Git configuration in Windows

Source: Internet
Author: User

Required Configuration:

1,C: \ Program Files \ git \ etc \ git-completion.bash:

alias ls='ls --show-control-chars --color=auto'

Note: Enter the LS command in git Bash to display Chinese characters normally.File Name.

2,C: \ Program Files \ git \ etc \ inputrc:

set output-meta onset convert-meta off

Note: git bash works properly.InputChinese, such as the Chinese commit log.

3,C: \ Program Files \ git \ etc \ profile:

export LESSCHARSET=utf-8

Note: unlike other VCs, the $ git log command rolls n logs from the beginning to the end. It will properly stop on the first page and press the Space key to flip the page. This is achieved by sending logs to less processing. The preceding Code sets less character encoding so that $ git log can display Chinese characters normally. In fact, its value does not have to be set to UTF-8, such as Latin1 ....... Another method is $ Git-no-pager log. If pagination is disabled in the options, you do not need to set the above options.

4,C: \ Program Files \ git \ etc \ gitconfig:
[Alias]
Go =
"! Bash-C \ "git pull & git Add .; if [\\\ "$ * \\\" =\\\ "\\\"]; then git commit-; else git commit-am \ "$ * \"; FI; git push origin master: Your-ID ;\""

NOTE: With this powerful alias, we only need to enter the $ git go command in 90%, eliminating the tedious steps of pulling and then committing and pushing.

Two usage methods:
$ Git go
Or
$ Git go AAA revision description

When the command is followed by a revision instruction, it will be submitted directly. It should be noted that there is a "AAA" before the "revision description", which is a bug. The first one in the parameter will be ignored, so you can write a random .......

If the revision instructions are not provided in the command line, an editor is automatically displayed, waiting for input. The default editor is vim. Vim is easy to use. First, you must understand that it has two modes: Command mode and input mode. The default command mode is used when Vim is started. You need to press the 'I' key to enter the input mode, and then edit it normally. After editing, switch the input method back to the English state, press ESC to enter the command mode again; then press'(Shift): WQ'And press Enter. W indicates writing, saving, and Q indicates exiting. Finished!

If you are not used to VIM, you can also set it to another Editor:

$ git config --global core.editor "notepad"

Notepad can be replaced with WordPad and notepad ++, which are more useful (but they cannot be directly accessed in the command line. You must set the PATH variable first ).

The above alias is customized for Windows and can be written more elegantly in Linux. However, since there are no differences in use, keep them consistent ~.

[GUI]
Encoding = UTF-8

Note: Our code library uses UTF-8 in a unified manner, so that the Chinese characters in the code can be normally displayed in the git gui.

[I18n]
Commitencoding = gb2312

Note: if this one is not found, although we can use $ git log locally to check that our Chinese revision is correct, I. Our log will become garbled after being pushed to the server; 2. Chinese logs pushed by others in Linux are also garbled after we pull. This is because our commit log will be first stored in the project. git/commit_editmsg file; in Chinese Windows, the newly created file uses gb2312 encoding; but git does not know that it is sent out as the default UTF-8, so garbled characters are generated. With this article, git will convert it to UTF-8 and then send it out, so there is no problem.

The above code is perfect for colleagues in Windows to push code in git bash. However, there are three problems:

1. The preceding alias $ git go bug indicates that a string of characters must be entered before code revision;

2. $ git diff. If the Code contains Chinese characters, garbled characters are displayed;

3. $ git checkout sometimes needs to modify/add or delete many files. If some files are occupied, they will be rejected by windows, resulting in failure, or even cause version library failure.

These three problems are all tolerable, and the first two should be able to solve them. The 3rd problems are attributed to the file system, which can only avoid checkout as much as possible. You should log out first when necessary, there will be no problem.

Related Article

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.