Home Development Tools git Version control tool Git - warehouse management.md

Version control tool Git - warehouse management.md

Jun 16, 2020 pm 03:41 PM
git

Today, let’s talk about Git warehouse management from two aspects. Create a warehouse and track changes to files in the warehouse.

Get the Git repository

There are two ways to get the git repository:

  • Change the local unused The initialized directory is used as the warehouse directory

  • Clone an existing Git project from the remote host

The following will demonstrate these two methods:

# mkdir learngit
# cd learngit/
# git init
Initialized empty Git repository in /root/learngit/.git
Copy after login

In this way, a local warehouse is established. Next, let’s see how to clone the repository remotely.

# mkdir learngit2
# cd learngit2
# git clone git@github.com:*****/blog.git  learngit2
Copy after login

This instruction means to clone the Git repository from the remote and change the directory to learngit2. By default, without this parameter, the directory name is blog.

Track every update of the warehouse

First of all, we need to talk about the status of the file. From a broad perspective, there are two statuses of the file. Type:

  • Untracked

  • Tracked

The tracked status is again Divided into Unmodified, Modified, and Temporary. An untracked file means that the repository does not track the file.

Version control tool Git - warehouse management.md

Below, we will demonstrate the status of these files.

First, create a new file in the project directory

# touch README.md
Copy after login

Then, let’s check the status of the file. git status can list the status of files. If no files are added, it means listing all.

# git status README.md 
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# README.md
nothing added to commit but untracked files present (use "git add" to track)
Copy after login

As you can see, the status of README.md is untracked. Now, let's create another file and add it to the staging area, and then look at the status of the file.

# cat > index.php <<eof
> <?php
> phpinfo();
> eof
# git add index.php
# git status index.php 
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
# new file:   index.php
#
Copy after login

As long as a file appears under Changes to be committed, it means that the file is in a temporary state. Then, modify the index.php file again and see what happens.

# git status index.php 
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
# new file:   index.php
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   index.php
#
Copy after login

Did you see that the index.php file appears in both the temporary storage area and the non-temporary storage area? Attention everyone! This situation occurs frequently.

git add

The functions of this command are to track new files, submit modified files to the temporary storage area, and merge the time Files with conflicts are marked with a resolved status.

View modifications

How to view modifications to files in the workspace and staging area. Just use git diff directly.

# git diff 1.txt 
diff --git a/1.txt b/1.txt
index 3b18e51..a042389 100644
--- a/1.txt
+++ b/1.txt
@@ -1 +1 @@
-hello world
+hello world!
Copy after login

So how to check the modifications in the staging area and warehouse. At this time, you need to add the --staged option.

# git diff --staged 1.txt 
diff --git a/1.txt b/1.txt
new file mode 100644
index 0000000..3b18e51
--- /dev/null
+++ b/1.txt
@@ -0,0 +1 @@
+hello world
Copy after login

To summarize

  • To view modifications to files in the workspace and staging area, use git diff [file name]

  • View modifications to the staging area and warehouse files, use git diff --staged [file name]

## to submit updates

We use git commit to submit updates and submit the contents of the staging area to the warehouse.

Generally, we like to use the -m option to write the update information submitted this time together. As follows:

# git commit -m &#39;first commit.add a txt file&#39;
Copy after login
If you do not add the -m option, an editor will pop up, allowing you to submit updated information in the editor.

If you update a lot of content and can’t finish it in one or two sentences, it is recommended to use this method.

The above is the detailed content of Version control tool Git - warehouse management.md. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1280
29
C# Tutorial
1257
24
How to download git projects to local How to download git projects to local Apr 17, 2025 pm 04:36 PM

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

How to update code in git How to update code in git Apr 17, 2025 pm 04:45 PM

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

How to update local code in git How to update local code in git Apr 17, 2025 pm 04:48 PM

How to update local Git code? Use git fetch to pull the latest changes from the remote repository. Merge remote changes to the local branch using git merge origin/&lt;remote branch name&gt;. Resolve conflicts arising from mergers. Use git commit -m "Merge branch &lt;Remote branch name&gt;" to submit merge changes and apply updates.

How to merge code in git How to merge code in git Apr 17, 2025 pm 04:39 PM

Git code merge process: Pull the latest changes to avoid conflicts. Switch to the branch you want to merge. Initiate a merge, specifying the branch to merge. Resolve merge conflicts (if any). Staging and commit merge, providing commit message.

What to do if the git download is not active What to do if the git download is not active Apr 17, 2025 pm 04:54 PM

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

How to solve the efficient search problem in PHP projects? Typesense helps you achieve it! How to solve the efficient search problem in PHP projects? Typesense helps you achieve it! Apr 17, 2025 pm 08:15 PM

When developing an e-commerce website, I encountered a difficult problem: How to achieve efficient search functions in large amounts of product data? Traditional database searches are inefficient and have poor user experience. After some research, I discovered the search engine Typesense and solved this problem through its official PHP client typesense/typesense-php, which greatly improved the search performance.

The top ten free platform recommendations for real-time data on currency circle markets are released The top ten free platform recommendations for real-time data on currency circle markets are released Apr 22, 2025 am 08:12 AM

Cryptocurrency data platforms suitable for beginners include CoinMarketCap and non-small trumpet. 1. CoinMarketCap provides global real-time price, market value, and trading volume rankings for novice and basic analysis needs. 2. The non-small quotation provides a Chinese-friendly interface, suitable for Chinese users to quickly screen low-risk potential projects.

How to delete branches of git How to delete branches of git Apr 17, 2025 pm 04:42 PM

You can delete a Git branch through the following steps: 1. Delete the local branch: Use the git branch -d &lt;branch-name&gt; command; 2. Delete the remote branch: Use the git push &lt;remote-name&gt; --delete &lt;branch-name&gt; command; 3. Protected branch: Use git config branch. &lt;branch-name&gt;.protected true to add the protection branch settings.

See all articles