-2

i have to commit the javascript file of only one component(ReactJS) in git..what is the command used for that..

my modified file which is located in E:\project\work\src\components\administration.js

please help me whether the below command is right or not?

git commit E:\project\work\src\components\administration.js -m "userAdminChanges"
Marek R
  • 32,568
  • 6
  • 55
  • 140
catherine
  • 11
  • 5
  • `git add filename` `git commit -m "magic changes"` – Marek R May 20 '19 at 09:10
  • also get familiar with some graphical git frontend. On windows IMO [GitExtention](http://gitextensions.github.io/) is the best. Doing commits there is very user friedly. – Marek R May 20 '19 at 09:14

2 Answers2

1

I guess, when i want to commit only one file i do:

git add E:\project\work\src\components\administration.js

git commit -m "UserAdminChanges"

hope that can help you !

Have a good day

PAYRE Quentin
  • 341
  • 1
  • 12
  • @catherine yep ! or just git push – PAYRE Quentin May 20 '19 at 09:26
  • 1
    Thanks a lot...committed successfully – catherine May 20 '19 at 09:29
  • 1
    You should explain what `git add` does, to not end up running sets of commands blindly. – padawin May 20 '19 at 09:32
  • @ PAYRE Quentin i have one more doubt , if i want to exclude one folder named config from committing to git... how to achieve that? – catherine May 20 '19 at 09:33
  • 1
    @catherine Create a file named .gitignore in your project's directory. Ignore directories by entering the directory name into the file (with a slash appended) (link : https://stackoverflow.com/questions/343646/ignoring-directories-in-git-repos-on-windows) – PAYRE Quentin May 20 '19 at 09:45
0

First you need to stage your changes, to tell Git: "This is what I want to commit", it is done with the add command, and it is to be done regardless of if the file is new or not:

git add E:\project\work\src\components\administration.js

You can stage multiple changes in multiple steps before commiting:

# Edit file1
# Stage it:
git add file1
# Edit file2
# Stage it:
git add file2

# Commits all staged changes (changes in file1 and file2):
git commit -m "Description about those changes"

For reference: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository

padawin
  • 4,230
  • 15
  • 19