Home > Article > Development Tools > 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 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!