Stage only selected files and commit them separately
Description: You changed index.html, about.html and style.css. Make two commits: one with the two html files and one with only the css file.
Hint:
- Stage the html files first with a pattern, commit, then stage the css file.
Solution
Terminal output
$ git add *.html
$ git commit -m "Update html pages"
[main 3f16559] Update html pages
2 files changed, 2 insertions(+), 2 deletions(-)
$ git add style.css
$ git commit -m "Update style"
[main 3ce526e] Update style
1 file changed, 1 insertion(+), 1 deletion(-)
$ git log –oneline
3ce526e (HEAD -> main) Update style
3f16559 Update html pages
333d1be Start
How it works
- The staging area lets us choose which files go in a commit.
- Two small commits are easier to review than one big commit.
Read Git Add.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |