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 understand Git Workflow

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

Share

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

This article introduces you how to understand Git workflow, the content is very detailed, interested friends can refer to, hope to be helpful to you.

The words written in the front:

Linus, as the Creator, not only created Linux, but also contributed to another NB in the software industry, which took two weeks to design and develop Git. Recently, I watched Linus's speech on Git in Google, and I had a deep understanding of the background and use of Git. There are three points that Linus itself considers for the code management system:

1. Distributed. Can meet the use of global development scenarios, can be developed offline, whether connected or not.

two。 Performance. Handle more commits and deal with a larger code base.

3. The content submitted is exactly the same as the content taken out, without any changes.

Throughout the presentation, Linus introduced how to maintain the code of 22000 modules in the Linux kernel, that is, ignoring 99.99% of pull request from around the world. Linus, as the Creator, only pays attention to the pull request of 15 gods around the world, and the other 99.99% of the pull request is never seen. Because the Creator only deals with God, only merges God's pull request; and then merges demons, Taoists, immortals, pull request; demons, Taoists, immortals, and then merges good, not good, sentient beings, and imbecile pull request (Linus is still contemptuous of sentient beings when he gives a speech at Google, saying that most people in Google are morons, well, what are we?) Suddenly enlightened, the original design concept of Git is closely related to the working environment and usage scene of Linus itself.

VSS, oh, no, don't get my mouth dirty.

CVS, oh, no, the embodiment of stupidity, imbecility, inefficiency, evil.

SVN, oh, no, the slogan is to do the best use of CVS, from the beginning of the positioning fell into a cliche, hopeless.

-- Linus

The following is a reprinted article about Git Quick start.

-

If you have background knowledge of Subversion, CVS, or other version management tools, please forget everything you are already familiar with about version control.

Git has a completely different version control approach to show us how it differs from other systems.

The Git is distributed, which means that when we clone the Git repository, we will get a copy of the warehouse for use on the local computer. In Git, you have your own code base, which you can change freely, commit as many times as you need, without worrying about contaminating the central repository, and then push the code to the central repository when you are sure.

Before diving into Git technology, let's take a look at a very clear Git workflow flow chart (thanks to the author, I also printed it on the desktop)

Take a look at the figure above: in Git, the code is stored in four different locations.

1. Remote repository

This is the Git remote repository-Remote repository, or a company-hosted cloud server. As the name implies, this code base is not saved on your local computer, nor do you often communicate with the remote repository. It will only be used when push after code changes.

2. Local repository

Local repository-Local repository is a code base that is created and stored locally when you clone a Git repository or create a new one.

Everything you do comes from this in the first place, because the local repository is stored on your local computer.

3. Index

Index-Index. I think this is one of the most confusing nouns in Git. This thing is halfway between the working copy of the code and the local repository.

It is a bit like a temporary area of code and can be used to temporarily track the files to be submitted. Later on, I'll introduce my git workflow and talk about how to use indexes. This code is also saved on the local computer.

4. Work area

Workspace-workspace. Here is the working directory where you create / edit / delete files, and these code files are stored in your local computing.

The above, I hope to give you the basic concept of Git. These are very important for using Git. Next, I'll introduce articles about my Git workflow. During this time, you can set up your Git environment at any time.

As we said earlier, we continue to share common ways to use Git in our daily work.

Suppose you have installed Git on your local computer and set the environment variable in PATH. In addition, we use the local repository to explain the concept, which means that we will create the repository locally instead of cloning it from the remote repository.

1. Create a Git repository

Open your favorite terminal tool, command prompt, and use the cd command to enter the directory. Then use the following command:

C:\ > cd vraa\ projects\ helloworld

C:\ vraa\ projects\ helloworld > git init

Initialized empty Git repository in C:/vraa/projects/helloworld/.git/

The above English tells me that I have created a new local repository and can track my own hello world projects.

2. Git configuration: user name and password

The next thing is to set up a user name and mailbox for my Git submission (commits)

This is an one-time setting after each Git installation.

C:\ vraa\ projects\ helloworld > git config-- global user.name "yourname"

C:\ vraa\ projects\ helloworld > git config-- global user.email "your@mail.com"

3. Add the file to the Git index and check its status

In this step, we will create a simple text file and use the git status command to see the impact of Git on the file, which will tell you the current state of the repository and branch details.

It's worth noting that you won't check any of your work in Git. Just modify the file directly and then submit your changes.

The command is as follows:

C:\ vraa\ projects\ helloworld > edit helloworld.txt

C:\ vraa\ projects\ helloworld > git status

# On branch master

#

# Initial commit

#

# Untracked files:

# (use "git add..." To include in what will be committed)

#

# helloworld.txt

Nothing added to commit but untracked files present (use "git add" to track)

Haha, Git knows there is a file, but hasn't tracked it yet. Well, we'll tell Git to track it, and that's what Git is really for.

C:\ vraa\ projects\ helloworld > git add.\ helloworld.txt

C:\ vraa\ projects\ helloworld > git status

# On branch master

#

# Initial commit

#

# Changes to be committed:

# (use "git rm-- cached..." To unstage)

#

# new file: helloworld.txt

Now, we use the git status command, which tells you a list of files that have been submitted. So, when we use git add [filename], we ask git to save the file in the git index to track its changes. This is simple. You can temporarily store this file here and commit all the files in the index together when you next commit.

3. Commit changes

With the commit command, we move the changed files from the index to the local repository. Unlike Subversion, committing means saving the code to a central repository.

In Git, even after the submission, the code will reside in the local repository and your changes will not be known to the outside world. Therefore, we can submit as many times as we like without fear.

C:\ vraa\ projects\ helloworld > git commit-m "initial commit"

[master (root-commit) 812befb] initial commit

Warning: CRLF will be replaced by LF in helloworld.txt.

The file will have its original line endings in your working directory.

1 files changed, 1 insertions (+), 0 deletions (-)

Create mode 100644 helloworld.txt

C:\ vraa\ projects\ helloworld > git status

# On branch master

Nothing to commit (working directory clean)

The above is the basic process of git workflow. Using Git, you can create a very simple commit and track changes

On how to understand the Git workflow to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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