Create a file in your new repository, add something to that file and commit that change with Git.
Commits
Commits are core to using Git. They are the moments in which you save and describe the work you've done. They are the ticks in the timeline of your project's history.
Create a New File
Now that you've got a repository started let's add a file to it.
Open your text editor and create a new empty file.
For example you can open the geany text editor, send it in the background (the & sign) and create a new empty file:
geany readme.txt &
Now write a little bit of text, perhaps type "Hello!", and save the file as 'readme.txt' in the 'hello-world' folder you created in the last challenge.
Check Status + Add and Commit Changes
Next check the status of your repository to find out if there have been changes. You know you have changed something, but does Git?
Make sure you're still within your 'hello-world' directory when you're running these commands. Use Git to see what changed in your repository:
First, check the status:
git status
Git should tell you that a file has been added.
Then add the file you just created so that it becomes a part of the changes you will commit (aka save) with Git:
git add readme.txt
Finally, commit those changes to the repository's history with a short (m) message describing the updates.
git commit -m "Created readme"
Step: Make More Changes
Now add another line to 'readme.txt' and save the file again.
In terminal, you can view the difference between the file now and how it was at your last commit.
Tell Git to show you the diff:
git diff
Now with what you just learned above, commit this latest change.
- Check status of changes to a repository
git status
- View changes to files
git diff
- Add a file's changes to be committed
git add <FILENAME>
- To add all files changes
git add .
- To commit (aka save) the changes you've added with a short message describing the changes
git commit -m "your commit message"