Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Git initializes to view the method of adding a submission

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "Git initialization view add submission method", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "Git initialization view add submission method" bar!

1. The most basic use of Git (1) initialize the local version library

To start using Git management for an existing project, simply go to the root directory where the project is located and execute the git init command.

Prepare a new Git local version library:

L@DESKTOP-T2AI2SU MINGW64 / JAccord gittel repositoryClearngit $git initInitialized empty Git repository in J:/git-repository/learngit/.git/

Note: after initializing the Git repository, there will be a directory called .git under the current directory, where all the data and resources needed by Git will be stored.

At present, however, we have only initialized all the files and directories in the Git repository according to the existing structural framework, but we have not yet started to track and manage any of the files in the project.

(2) View the status of the file

Use the git status command to view.

Go to the local version library to view the status of files in the workspace and temporary storage area.

# execute the command `git status` command L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git status# to work on the main branch On branch master# has not yet submitted a file, which means that no file has been submitted in the local library. No commits yet# does not need to commit (files can be created / copied and tracked with "git add") # No commit means that there is no committable file in the staging area # tracking file is to let Git manage the file. Nothing to commit (create/copy files and use "git add" to track) (3) add files to the staging area

1) check the status of the file in the workspace and temporary storage area after creating the file.

After we create a readme.txt file in the repository directory, we execute the git status command.

# create readme.txt file L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $touch readme.txtL@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $lltotal 0RW j/git-repository/learngit r Muir-1 L 197121 April 4 00:38 readme.txt# View Workspace, staging area status L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch master# has no submission yet It means that no files have been submitted in the local library. No commits yetUntracked files: (use "git add..." To include in what will be committed) readme.txt # file name is Red nothing added to commit but untracked files present (use "git add" to track)

Description:

Untracked files:readme.txt

Indicates that an untracked file readme.txt is found

Use "git add..." To include in what will be committed

For readme.txt files, you can use the git add command to add new files to the staging area.

Nothing added to commit but untracked files present (use "git add" to track)

Indicates that you have not added anything to the staging area, but there are untracked files that can be tracked using the "git add" command.

2) add the files from the workspace to the staging area.

Execute the git add command to add the readme.txt file to the staging area.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git add readme.txtwarning: LF will be replaced by CRLF in readme.txt.The file will have its original line endings in your working directory

Description:

Warning: LF will be replaced by CRLF in readme.txt.

The file will have its original line endings in your working directory

Warning: the newline format in the readme.txt file will be replaced, and CRLF will replace LF.

The option we selected when we installed step 8 of Git. This is something at the bottom of Git. We don't have to control it.

But the file is in your working directory, and it is still in the newline format of the original file.

LF is the newline character in Linux system, while CRLF is the newline character in Windows system. Since our file is created under the Linux system (created in Git Bash) and saved in the Windows system, the line Terminator in the file should be wrapped in the CRLF format under Windows.

The above two lines are a hint and have no actual effect on our operation.

3) check the status of the workspace and staging area again.

Execute the git status command to view the status of the workspace and staging area.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch masterNo commits yetChanges to be committed: (use "git rm-- cached..." To unstage) new file: readme.txt # file name is green

Description:

Changes to be committed: new file: readme.tx

Changed: new readme.txt file created

Use "git rm-- cached..." To unstage

It is suggested that you can apply "git rm-cached..." Command

Withdraw the file from the staging area to the workspace.

Summary:

As long as the file is displayed under the line "Changes to be committed", it is in a temporary state.

If you submit at this time, then the version of the file at this moment will be retained in the history.

You can indicate the file or directory path to trace after the git add command.

If it is a directory, it means that all files in that directory should be tracked recursively. (in fact, the subtext of the git add command is to put a snapshot of the target file into the staging area, while files that have not been tracked are marked as tracked. )

4) withdraw the file from the staging area to the workspace.

Execute the git rm-- cached command to recall the readme.txt file from the staging area to the workspace.

And execute the git status command to view the status of the workspace and staging area.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git rm-- cached readme.txtrm 'readme.txt'L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch masterNo commits yetUntracked files: (use "git add..." to include in what will be committed) readme.txt # file is called Red nothing added to commit but untracked files present (use "git add" to track)

As you can see, the readme.txt file becomes a file that is not tracked by Git.

(4) submit the contents of the temporary storage area to the local version library

When the temporary storage area is ready to submit, please make sure that there are any changes before that, or the new files have not been git add to the temporary storage area, otherwise the changes that have not been temporarily saved will not be recorded when you submit.

So, before you prepare to submit each time, use git status to see if all the files you need to submit have been temporarily saved, and then run the submit command git commit-m 'remarks'.

1) add the file to the cache and submit it to the local version library.

Add the readme.txt file to the staging area, and execute git commit-m 'instructions for this submission' to submit the readme.txt file to the local version library.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git add readme.txtwarning: LF will be replaced by CRLF in readme.txt.The file will have its original line endings in your working directoryL@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git commit readme.txt-m'My first commit.new file readme.txt'warning: LF will be replaced by CRLF in readme.txt.The file will have its original line endings in your working directory [master (root-commit) e84b93b] My first commit.new file readme.txt 1 file changed 1 insertion (+) create mode 100644 readme.txt

Highlight the bottom three lines:

Master: represents the master (backbone) branch.

Root-commit:root stands for root, which means the first commit of the version library.

E84b93b: a summary of the version number of the submission operation.

My first commit.new file readme.txt: the description of this submission.

1 file changed: a file was modified.

1 insertions (+): one line has been added, the + sign indicates increase, and the-sign indicates decrease.

Create mode 100644 readme.txt:readme.txt file creation mode is 100644

100 stands for regular file (normal file), and 644 for file permissions.

Tip: a snapshot placed in a temporary storage area is recorded at the time of submission.

That is, each time you perform a commit operation, you take a snapshot of the project, which you can return to or compare with later.

2) the status of the workspace and temporary storage area after submitting the file to the local version of the library.

Execute the git status command to view the status of the workspace and staging area.

There is no committable content in the L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch master# staging area # the working directory is the same as the local version library, with no modification, new, and so on. Nothing to commit, working tree clean

3) check the status of the workspace and temporary storage area after modifying the contents of the file.

After modifying the contents of the readme.txt file, execute the git status command to check the status of the workspace and staging area.

# modify the contents of the file L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $echo "git world" > > readme.txtL@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $cat readme.txthello git worldgit world# to view the status of the workspace and temporary storage area. L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch masterChanges not staged for commit: (use "git add..." To update what will be committed) (use "git restore..." To discard changes in working directory) modified: readme.txt # file name is red no changes added to commit (use "git add" and/or "git commit-a")

Description:

Changes not staged for commit:modified: the readme.txtreadme.txt file was modified but not added to the staging area

Use "git add..." To update what will be committed means for readme.txt files, you can use the git add command

Add file updates to the staging area.

And step (2)

Use "git add..." To include in what will be committed is a little different.

Use "git restore..." To discard changes in working directory means that you can use git restore. Command to discard changes to files in the working directory.

Is to restore the file. In previous versions of Git, the command was git checkout--...

No changes added to commit (use "git add" and/or "git commit-a") indicates that you have not added changes to be submitted

And/or means you can use "git add" to add the change file to the staging area.

After submitting to the local version library through "git commit-a"

You can also submit the changed files directly to the local version library through "git commit-a".

Note that you use the git commit-a command with the file name added.

4) submit the modified file to the temporary storage area.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git add readme.txtwarning: LF will be replaced by CRLF in readme.txt.The file will have its original line endings in your working directoryL@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git statusOn branch masterChanges to be committed: (use "git restore-- staged." To unstage) modified: readme.txt # file name is green

Description:

Changes to be committed: modified: readme.txt

Changes to readme.txt have been tracked by Git

Use "git restore-- staged..." To unstage

You can use git restore-- staged. Command

Withdraws the file from the staging area, but does not undo the changes to the file.

5) submit the modified file to the local version library.

L@DESKTOP-T2AI2SU MINGW64 / j/git-repository/learngit (master) $git commit readme.txt-m'modified readme.txt'warning: LF will be replaced by CRLF in readme.txt.The file will have its original line endings in your working directory [master e704334] modified readme.txt 1 file changed, 1 insertion (+)

As you can see, there is no (root-commit) after master, because the root commit is only once.

The newly created file is added to the staging area and then to the local version library.

The files that have been submitted to the local version library can be modified, you can follow the above operation, or you can submit them directly to the local version library.

2. Summarize the Git command serial number used in this article. The Git command explains that 1git init initializes the local version library. 2git status views the status of the current workspace and staging area files. 3git add... You can add files to the staging area. 4git commit-m''submits the update. Thank you for your reading, the above is the content of "Git initialization view the method of adding submission". After the study of this article, I believe you have a deeper understanding of the problem of Git initialization view adding submission method, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report