Alex, a bright-eyed new developer, was eager to dive into his first open-source project 🚀. The project’s code was hosted on a remote repository, and Alex’s first task was to get a local copy. He opened his terminal and typed:
git add . is a Git command used to stage all changes made to a working directory, before committing them.
Here is an example:
Suppose you made changes to two files named file1.txt and file2.txt. You want to include both changes in your next commit. To do so, first navigate to the project directory in the terminal and execute:
git add .
This command stages all of the changes made in repository. You can now review the changes staged by executing:
git status
You should see that file1.txt and file2.txt have been staged. Now you can commit the staged changes by running:
The git status command displays information about the current status of the working directory and staging area in your Git repository. It tells you which files are currently being tracked, which changes have been staged, and which changes still need to be staged.
Let’s say you’re working on a new feature for your website and you’ve made some changes to your code. You can use git status command to see which files have been edited on your local copy:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout --<file>..." to discard changes in working directory)
modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
In this example, Git is reporting that the index.html file has been modified but not yet staged. This means that Git is aware of the changes you have made, but they have not yet been added to the next commit.
I hope that helps! Let me know if you have any other questions.
The git commit command is used in Git to save changes to a local repository. It creates a new commit object with a unique identifier based on the changes made, along with a message that describes the changes. This allows you to keep track of changes made to your code over time and makes it easy to revert to previous versions if necessary.
Here’s an example of how to use git commit:
After making changes to your files, add them to the staging area with git add.
Once you’ve added all the changes you want to commit, run the git commit command followed by a -m flag and a message inside quotes describing the changes made. For example:
git commit -m "Added new feature to login page"
The commit is now saved to your local repository with a unique identifier, allowing you to easily track and revert to previous versions of your code.
It’s important to note that committing changes locally only saves them to your local Git repository. To share the changes with others or push them to a remote repository, you’ll need to run git push after committing.
git add is a Git command used to stage changes made to a working directory, before committing them. Staging is an intermediate step that allows you to control which changes are included in the next commit and which are not.
Here is an example:
Suppose you made changes to two files named file1.txt and file2.txt. You want to include the changes to file1.txt in your next commit, but not the changes to file2.txt.
To do so, first navigate to the project directory in the terminal and execute:
git add file1.txt
This command stages the changes made to the file file1.txt. You can now review the changes staged by executing:
git status
You should see that file1.txt has been staged.
Now you can commit the staged changes by running:
git commit -m "Added new feature to file1.txt"
The commit will include only the changes to file1.txt since file2.txt was not staged.
git log is a command in Git used to display the commit history of a repository. When run, it shows the author, date, and commit message of all commits in reverse chronological order. The latest commit appears at the top of the list.
Here’s an example:
$ git log
commit b4691c6fd3feb96eed5b51c4f9ebdd5738cde0eb (HEAD -> main, origin/main, origin/HEAD)
Author: John Doe <[email protected]>
Date: Fri Jul 23 15:51:47 2021 -0400
Add new feature
commit 0e94d82558f8c8ed494e7714c7bc28c41462a9e1
Author: Jane Smith <[email protected]>
Date: Thu Jul 22 11:24:35 2021 -0400
Update documentation
commit 3028c5a76d78f6c673296b059b452fe466305d20
Author: John Doe <[email protected]>
Date: Wed Jul 21 09:17:26 2021 -0400
Fix bug in login feature
In this example, the git log command lists the three most recent commits in the repository, showing the commit hash, the author, the date, and the commit message for each one.