Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does git create an extension to add files to the version library

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "git how to create an extension to add files to the version library". In daily operation, I believe many people have doubts about how to create an extension to add files to the version library in git. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "how to create and expand files to add files to the version library". Next, please follow the editor to study!

1. Create a version library

Step 1: choose a suitable place and create an empty directory:

$mkdir learngit$ cd learngit$ pwd/Users/michael/learngit

The pwd command is used to display the current directory location.

If you are using the Windows system, to avoid all kinds of inexplicable problems, please make sure that the directory name (including the parent directory) does not contain Chinese.

Step 2: use the git init command to turn this directory into a repository that Git can manage:

$git initInitialized empty Git repository in / Users/michael/learngit/.git/

Git built the warehouse in an instant, and told you that it is an empty warehouse (empty Git repository). Careful readers can find that there is a .git directory under the current directory, this directory is Git to track and manage the version library, do not manually modify the files in this directory, otherwise change the chaos, it will destroy the Git warehouse.

If you don't see the .git directory, it's because the directory is hidden by default and can be seen with the ls-al command.

2. Add the file to the version library (1) first of all, let's make it clear here.

In fact, all version control systems can only track changes to text files, such as TXT files, web pages, all program code, etc., and Git is no exception. The version control system can tell you every change, such as adding a word "Linux" in line 5 and deleting a word "Windows" in line 8.

Although the binary files such as pictures and videos can also be managed by the version control system, they cannot track the changes of the files. They can only string up the binary files every time they are changed, that is, they only know what the picture has changed from 100KB to 120KB, but the version control system does not know and cannot know what has changed.

Unfortunately, Microsoft's Word format is binary, so the version control system cannot track changes to Word files, and if you really want to use the version control system, you have to write the file in plain text.

Because the text is encoded, for example, there is a commonly used GBK encoding in Chinese and Shift_JIS encoding in Japanese. If there are no problems left over from history, it is strongly recommended to use the standard UTF-8 encoding. All languages use the same encoding, which is not conflicted and is supported by all platforms.

(2) Children's shoes using Windows should pay special attention to:

Never use notepad that comes with Windows to edit any text files. The reason is that the Microsoft notepad team used a very retarded behavior to save UTF-8-encoded files. They cleverly added 0xefbbbf (hexadecimal) characters at the beginning of each file, and you will encounter a lot of incredible problems, for example, the first line of the web page may show a "?", the correct program will report syntax errors as soon as it is compiled, and so on, which are all brought about by the mentally retarded behavior of notepad.

It is recommended that you download Notepad++ instead of notepad, not only powerful, but also free! Remember to set the default encoding of Notepad++ to UTF-8 without BOM.

As shown in the following figure:

(3) add files to the version library

To write a readme.txt file, be sure to put it in the learngit directory (or a subdirectory), because the learngit directory is a Git repository just created with the git init command above, and Git can't find it anywhere else.

Compared with three steps to put an elephant in the refrigerator, it takes only two steps to put a file in the Git warehouse.

The first step is to tell Git with the command git add command to add the file to the repository:

$git add readme.txt

Execute the above command without any display, which is right. Unix's philosophy is "no news is good news", indicating that the addition is successful.

The second step is to tell Git with the command git commit command to submit the file to the warehouse:

$git commit-m "wrote a readme file" [master (root-commit) eaadf4e] wrote a readme file 1 file changed, 2 insertions (+) create mode 100644 readme.txt

Explain it briefly.

The git commit command, followed by-m, is a description of this submission. You can enter anything, preferably meaningful, so that you can easily find the change record in the history.

When the git commit command is executed successfully, it will tell you:

File changed:1 files have been changed (our newly added readme.txt file)

Insertions: two lines are inserted (readme.txt has two lines).

Why does Git need add,commit to add files in a total of two steps?

Because commit can submit many files at a time, you can add different files multiple times.

For example, the following example:

$git add file1.txt$ git add file2.txt file3.txt$ git commit-m "add 3 files." 3. Summary

1) initialize a Git repository, using the git init command.

2) add files to the Git repository.

There are two steps: use the command git add, note that it can be used repeatedly to add multiple files, and use the command git commit-m to finish.

3) the Git command used in the text.

The serial number Git command states that 1git init turns a directory into a warehouse that can be managed by Git. 2git add can put the tracked updates to the temporary storage area (updates include new, modify, delete, etc.) 3git commit-m 'add Test_text' submits updates to the warehouse here, on the "git how to create an extension to add files to the version library" on the end of the study, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report