Version control tool Git - warehouse management.md
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
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
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.
Below, we will demonstrate the status of these files.
First, create a new file in the project directory
# touch README.md
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)
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 #
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 #
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!
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
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 'first commit.add a txt file'
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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

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 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/<remote branch name>. Resolve conflicts arising from mergers. Use git commit -m "Merge branch <Remote branch name>" to submit merge changes and apply updates.

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.

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

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.

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.

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