Reputation: 29477
I created a private GitHub repo, say https://github.com/myuser/myprivrepo, and chose to have it generate a .gitignore
and README.md
for me. I then cloned this repo locally and added a bunch of files. I also modified both my .gitignore
as well as the README.md
that GitHub had generated for me.
I then did this:
git commit -a -m "Initial commit with basic project structure."
And then this:
git push
It asked me to authenticate, I did, and the "push" seemed to be successful. So I go back into my GitHub repo, and after refreshing the page, I still only see my two GitHub-generated files (.gitignore
and README.md
), however they have been updated with my changes and even show a correctly-updated timestamp and commit message ("Initial commit with basic project structure.") next to them.
So it's like the push honored the two GitHub-generated files being changed, but ignored all my other changes. Here is my .gitignore
:
*.class
.mtj.tmp/
*.jar
*.war
*.ear
hs_err_pid*
.metadata
.gradle/
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.project
.externalToolBuilders/
*.launch
.cproject
.classpath
.buildpath
.target
.texlipse
And an example of a file that I added but that is not present on GitHub is build.gradle
, which shouldn't be getting matched by anything in the ignore file. Thoughts?
Note: When I right-click my local repo root dir and go to Git Gui
I see that all the files that are missing on GitHub are showing up locally as "Unstaged". Not sure if that means anything.
Upvotes: 0
Views: 508
Reputation: 5844
It seems GitHub is fine. When you do a git commit -a
, all the files that git was already tracking are committed, which in your case will be just the files generated by GitHub. New files will not be committed unless you git add <file>
or git commit <file>
. To check which files git is tracking, use git ls-tree -r master --name-only
. It may also be useful to do a git status
before commiting:
$ git status
On branch 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)
### Files which will be committed with git commit -a appear here
Untracked files:
(use "git add <file>..." to include in what will be committed)
### Files which will NOT be committed with git commit -a appear here
no changes added to commit (use "git add" and/or "git commit -a")
To fix your current problem, you could do:
$ # uncommit last commit
$ git reset HEAD~1 --soft
$ # add missing file
$ git add build.gradle
$ # recommit
$ git commit -a -m "Initial commit with basic project structure."
$ # force the push, as git will complain about overwriting a commit
$ git push --force
Upvotes: 1
Reputation: 15189
git commit -a
does not add files that were previously untracked. You can use git add .
to add everything prior to the commit. The -a
is not needed anymore then.
Quoting the commit manual (emphasis mine):
-a
--allTell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
Upvotes: 1