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 to update files to version library in git

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to update files to the version library in git, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Initialize the version library

It was just mentioned that we can simply think of a version library as a directory, we can first create a directory git_test to act as a version library, and then we can version manage all the files in this directory. So how do we create a version library? When we enter the git_test directory, right-click and select Git Bash Here, which will open the console. At this time, you only need to enter the command git init to complete the initialization of the version library, that is, to create the version library of git_test.

You can see that after the successful execution of the git init command, the git_test folder generated a .git directory. The .git directory can actually be understood as the version library of Git, which is used by Git to manage different version libraries. In general, manual modification is not allowed, otherwise the version library may be destroyed and lost. When our version library is successfully created, we can use this version library to version all the files in different formats in the git_test directory. After talking about creating a version library, we have to talk about how to upload the files under the directory to the version library. Generally speaking, it takes two steps to upload files to the version library:

Use the git add directive to add files from the git_test directory to the staging area, and you can add multiple files to the staging area.

After uploading all the files that need to be updated to the version library to the staging area, use the git commit directive to update the staging area files to the version library.

The step mainly involves three keywords, the git_test directory is equivalent to the working directory, all the files we usually work in this working directory, the version library is actually the .git directory just mentioned, what does this .git contain? In fact, there are three important things in the version library: the temporary storage area, the main branch master, and the pointer to the current branch. We just talked about the need to add the file to the staging area before commit commits it to the version library. Why is the concept of temporary storage area needed? We can imagine this logic: if my local version update needs to update 10 files, if there is no concept of temporary storage area, I may need to submit files to the version library ten times, so that there will be multiple different versions. But once I have the staging area, I can add 10 files to the staging area multiple times, and then submit all the changes to the staging area directly to the version library in one commit. After talking about the concept of staging area, let's take a look at how to upload files to the version library.

We now have a file hello.txt under the git_test working directory, and now we need to upload it to the version library in two steps, we need to use the git add hello.txt instruction to add to the temporary storage area, and then use the git commit-m 'submit comments' directive to submit the temporary storage area for modification to the version library.

We can see the screenshot above, first use git add to add files to the temporary storage area, and then use git status to check the status will tell us that it has not been submitted to any version before, and there is a new file hello.txt in the temporary storage area, and there are three local files or directories that have not been committed to the temporary storage area. Finally, use git commit to submit changes to the version library. It returns 1 file changed, 1 insertion, which means that a file has been modified and a new line has been added. Here we submit a modified file to the version library to implement, I recorded a simple git diagram to see the specific process:

Git add instruction

Let's first look at the first instruction, git add. Just now we can add a file to the staging area using the git add filename. Of course, there are many forms of git add commands. Here I list several forms of git add instructions that we often use:

Git add hello.txt adds hello.txt to the staging area git add. Add all files in the working directory to the temporary storage area git add * score add files ending with score to the temporary storage area, such as addscoregit addscore * add files that begin with score to the temporary storage area, such as scoreInfo.txtgit add project/*.md add all md files under the project directory git add-u [path] add modified files in all files managed under path to the temporary storage area We can simply take a look at the following recorded gif for path selection:

We tested each command, and then git status looked at the update of the staging area relative to the local directory, and finally git reset HEAD knew the staging area data so that we could clearly compare the changes of each command staging area file. We can find that basically these git add commands can satisfy almost all of our operations of adding files to the staging area.

Git commit instruction

The git commit directive actually commits all changes to the staging area to the version library. Here the git commit instruction actually has three main commands:

Git commit-m 'submit remarks' submit temporary area to the version library and add submission comments git commit-a-m 'submit comments' first git add all files managed by the version library and then submit them directly to git commit-- amend incremental submission, which will be submitted on the basis of the parent node. Here, it is mainly recommended to submit in two ways: 1 and 3, and the second is not recommended. The first is to git add the file to the staging area every time, and then commit to the version library. The second can be managed by Git and modified but not added to the temporary storage area can also be submitted to the version library, we usually take the initiative to use git add to the temporary storage area and then submit. The third is incremental submission, a very simple example, you have completed your work today, submitted a version 2019-12-31, just submitted found a bug, adjusted you do not want to resubmit a version, then you can use-- amend parameter incremental commit, so that we can add our new changes to the last commit code without adding a new commit-id. Next, let's take a look at the following example operation of the gif diagram:

Thank you for reading this article carefully. I hope the article "how to update files to version library in git" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Internet Technology

Wechat

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

12
Report