More about Tracking Files
Glissez pour afficher le menu
When working with Git, files in your project directory can be either tracked or untracked. Tracked files are included in snapshots (future commits), while untracked files are not. Newly created files are typically untracked until added to the staging area.
Tracked files can exist in three states:
- Modified: changes have been made, but Git has not stored them yet;
- Staged: changes are prepared to be committed and included in the next snapshot;
- Committed: changes are saved in a snapshot inside the
.gitdirectory.
Use the following image to illustrate these states clearly.
If a file is already tracked and changes are made to it, you must run the git add command to stage those modifications.
Modify the test.txt file using the following command:
echo "Never give up" >> test.txt
The >> operator appends the text enclosed in double or single quotes to an existing file, in this case test.txt.
The text is added at the end of the file on a new line.
Now the file has a modified status.
Use the git add, git status, and git commit commands to stage the change, check the status of the working tree and staging area, and commit the change, respectively:
git add test.txt
git status
git commit -m "Add a new line"
As you can see, the changes are now staged, and a new snapshot of the project has been created by committing the staged changes.
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion