Git add and submit files and view

Table of contents

1. Git add

Two, Git submit files

3. View the commit history and current status of the Git repository


1. Git add

1. In the terminal or command prompt, navigate to the directory where your Git project is located, and use the cd command to switch directories.

2. In the target directory, run the following command to initialize a new Git repository, which will create a hidden folder named .git in the current directory , which is the core part of the Git repository.

git init

3. Use the following command to add files to Git's staging area (Staging Area), which will add all newly created or modified files to the staging area (need to create a new file with content in it).

git add 文件名

If you have multiple files to add, you can use the following command to add multiple files at once:

git add 文件名1 文件名2 ...

If you want to add all files in the entire directory, you can use the following command:

git add .

4. Make sure you have added all the files to be submitted. You can use the following command to view the status of the current files, which will show which files have been added to the staging area and which files have not been added.

git status

This means that you have successfully added a file named one/newfile.txt to the staging area of ​​your Git repository.

Two, Git submit files

1. Use the following command to submit the files in the temporary storage area to the Git warehouse, and replace the submission description with a brief description of the submission, such as fixing a bug, adding new functions, etc.

git commit -m "提交说明"

3. View the commit history and current status of the Git repository

To view the commit history and current status of a Git repository, you can use the git log and git status commands.

1. The git log command is used to display the commit history of the Git repository. Execute the following command in the terminal, which will display the recent commit record, including the author of each commit, commit date and commit message, etc.

git log

2. Some common options of the git log command:

(1) git log --oneline : Display the commit record in a concise one-line form.

(2) git log -n <number> : Only display the latest specified number of commit records.

(3) git log --author=<author> : Only display the submission records of the specified author.

(4) git log --grep=<keywords> : Only display the submission records containing the specified keywords.

(5) git log --since=<date> : Only display commit records after the specified date.

(6) git log --until=<date> : Only display the commit records before the specified date.

3. The git status command is used to view the status of the current Git repository, including files that have been modified but not staged, changes that have been staged but not submitted, etc. Execute the following command in the terminal:

git status

This will show information such as the name of the current branch, files modified but not staged, changes staged but not committed, etc. If there are no uncommitted changes, the output will show "nothing to commit, working tree clean", currently There aren't any uncommitted changes and the workspace is clean.

Guess you like

Origin blog.csdn.net/m0_67906358/article/details/131335550