I'm fairly new to using git and I've dug myself in to a hole a couple of times where one of my git commits ends up modifying files that do not show up when doing a git status
. I'm curious if anyone knows might cause my local repository to get in to such a state since I seem to need to re-clone the repository to fix my issue.
An example git status with one unstaged file.
User@User-DESKTOP:~/code/tap$ git status
On branch what-is-programming
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: exampleFile.cs
no changes added to commit (use "git add" and/or "git commit -a")
Then I add the file
User@User-DESKTOP:~/code/tap$ git add .
warning: LF will be replaced by CRLF in exampleFile.cs
The file will have its original line endings in your working directory
Then I commit the file
User@User-DESKTOP:~/code/tap$ git commit -m "some message" [what-is-programming bd86d6b] some message
3 files changed, 88 insertions(+), 186 deletions(-)
create mode 100644 someFileIDontExpect.cs
delete mode 100644 anotherFileIDontExpect.cs
If I do a diff against the previous commit it shows what I expect
User@User-DESKTOP:~/code/tap$ git diff --name-status HEAD~
M exampleFile.cs
Same if I diff against master
User@User-DESKTOP:~/code/tap$ git diff --name-status master
M exampleFile.cs
But when I push to github, it shows me creating someFileIDontExpect.cs and deleting anotherFileIDontExpect.cs.
The potential places I see me doing "weird" stuff that I sometimes do a git commit -m "WIP"
and then later a git reset --soft HEAD~
to continue working on the WIP commit. I've found the workflow better than git stash
but maybe it creates issues? I'm not exactly sure how to figure out what is broken since diffing my commit seems fine but once it gets to github it is very much in an unexpected state.
We're also using git-lfs but this is occurring with source files so I'm not sure it's having an impact.
Thanks for any insight you could provide! I'm very curious how I'm breaking things.
EDIT
@mkrieger1 you're right that git add .
adds all the files in my working directory but git status
did not show any other unstaged files. Also the git diff of my commit shows no other added or modified files.
@matt I'm not sure I follow. git diff --name-status HEAD~
should list the added or modified files from the previous commit right? It shows only the exampleFile.cs
as being modified even though my commit message showed someFileIDontExpect.cs
being created and anotherFileIDontExpect.cs
being deleted. I expect git diff --name-status master
to show me the changes in my branch what-is-programming
that are not in master
and they also show just exampleFile.cs
as being modified. My local copy of master
matches the remote so why when I push do the two other files show up in a pull request? Is there something I should be diffing against to see what will show up in my pull request?