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 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!

Git and GitHub are essential tools for modern developers. 1. Use Git for version control: create branches for parallel development, merge branches, and roll back errors. 2. Use GitHub for team collaboration: code review through PullRequest to resolve merge conflicts. 3. Practical tips and best practices: submit regularly, submit messages clearly, use .gitignore, and back up the code base regularly.

Git and GitHub are not the same thing: Git is a distributed version control system, and GitHub is an online platform based on Git. Git helps developers manage code versions and achieve collaboration through branching, merge and other functions; GitHub provides code hosting, review, problem management and social interaction functions, enhancing Git's collaboration capabilities.

After installing Git, in order to use more efficiently, the following settings are required: Set user information (name and mailbox) Select text editor Set external merge tool Generate SSH key settings Ignore file mode

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

Causes of slow Git downloads include poor network connections, Git server problems, large files or large submissions, Git configuration issues, insufficient computer resources, and other factors such as malware. Workarounds include improving network connectivity, adjusting firewall settings, avoiding downloading unnecessary files or submissions, optimizing Git configuration, providing adequate computer resources, and scanning and removing malware.

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.

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

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.


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

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!