0

I am new to Git and am really struggling to get my head 'round how it works.

Here's the situation: I worked on a simple .css change, and pushed it to Github. No dramas there. A few days later I realised I had made a mistake in the CSS file and so checked out that branch to fix my mistake. I fix the code and do a git status just to check everything, but I see about 100 other files appear in my 'Changes to be committed list'.

None of these files have anything to do with what I've been working on, so I figure someone might have added to my branch on GitHub. I go to GitHub and check but on my branch's page but I only see my 1 file and 1 commit. I don't know where these other files have come from, but obviously it was probably when I checked out.

Would anyone know what's happened here?

Also, how do I push just my files? I don't want to push a whole heap of others.

MeltingDog
  • 14,310
  • 43
  • 165
  • 295
  • 1
    Possible duplicate of [How do I commit only some files?](http://stackoverflow.com/questions/7239333/how-do-i-commit-only-some-files) – Roman Dec 01 '16 at 04:44

3 Answers3

2

If you had other files on your local directory, you likely did a git add .. In general, add the specific file you want to track in git. git reset will undo all staged changes. Then commit the change to the file you want to change, and push.

aikramer2
  • 1,283
  • 12
  • 9
  • If I added them when I last pushed wouldn't I see them (the other files) in Github? (not debating, just asking) – MeltingDog Dec 01 '16 at 04:48
  • If you added them then committed before pushing, yes. But if you ran git add . after the commit then no. – aikramer2 Dec 01 '16 at 04:49
  • 1
    Variations of this question have been asked before (probably more than once). It's usually better to close such questions as duplicates and link to the duplicate answer. That way if the information ever gets out of date (maybe new git features is added that makes this simpler), it only needs to be updated in one place. – Roman Dec 01 '16 at 04:50
  • 1
    I think we don't want to jump the gun here. The "changed" files could have a number of reasons, such as line ending problems. If you are certain that you only want the changes you made, then reset the other files and make your commit. – Tim Biegeleisen Dec 01 '16 at 04:50
  • @aikramer2 ah I see what you mean. No, I ran the git status before adding or committing anything. All I've done in this 'session' was checkout the branch, make the changes to the file then run git status. – MeltingDog Dec 01 '16 at 04:57
1

If you want to commit only your file use the command

git commit [some files]

I assume you have not added any new files, so 'add' command is not necessary.

Please refer this answer for detailed explanation

Community
  • 1
  • 1
Raghu
  • 450
  • 1
  • 5
  • 15
1

git add file1.css file2.css file3.css

git commit -m "msg"

git push

Duyet Nguyen
  • 543
  • 3
  • 11