Git is a very common and popular version control tool that makes it easy to track and manage project changes. In actual application processes, files are often added or deleted. Next, we will introduce in detail how to add and delete files in Git.
The way to add files is very simple, just use Git’s add
command. Suppose we need to add a file named example.txt
, then perform the following operations:
git add example.txt
After executing the above command, Git will add the file to the staging area. At this point, we can use the git status
command to view the current status:
$ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: example.txt
You can see that Git has added the example.txt
file to the list of upcoming submissions (That is, the temporary storage area).
If you want to commit all changes in the staging area at once, you can use the git commit
command:
git commit -m "add example.txt file"
After executing the above command, Git will create a new Commit and apply the changes in the staging area to the commit.
Deleting files is also easy, just use Git's rm
command. Suppose the file name we need to delete is example.txt
, then perform the following operations:
git rm example.txt
This operation will delete example.txt## from the local file system # file and add a corresponding record in the staging area. If you want to delete this file from the repository, you need to submit it again:
git commit -m "delete example.txt file"
The above is the detailed content of How to add and delete files in Git. For more information, please follow other related articles on the PHP Chinese website!