0

Problem I have file A. When I run a windows bat file, file A's contents get changed. git status however does NOT show the file as modified - even though I can see the changes. I am quite familiar with git, but this issue is baffling me.

More details

  1. The file is not being git ignored.
  2. git update-index --really-refresh had no effect.
  3. Assume unchanged is not set.
  4. --skip-worktree on the file is not set.
  5. There is no extraneous .git directory in there.
  6. The batch file uses windows attrib, erase, and copy functions to change the file.
  7. If I open the file with a text editor, change something, then save the file - git status shows my new change AND all of the changes I was expecting before (with a git diff). And after doing this, it seems to work fine for a time.
  8. Windows 10 and git 2.18.0
  9. It happens in both git bash and windows cmd git.
  10. My teammates are also seeing the same exact issue on similar env setups.

Any ideas? It seems like the way the batch file is modifying the file is somehow circumventing whatever git status uses to identify changed files.

Desired/Expected Behavior I'd expect git status to show me the changes after running the batch file, without me having to manual interact with the file.

Thank you.

Batch File contents It is relatively simple (I generalized vars and removed display outputs).

setlocal
cls
attrib -r %HOME%\%TARGET_FILE%
erase %HOME%\%TARGET_FILE%
copy %SOURCE_FILE% %HOME%\%TARGET_FILE%
call gradle doSomething // This runs a gradle task that changes other files. These files do not have an issue, only the ones changed using attrib, erase, copy
pause

Redacted Git Config

$ git config --list    
http.sslcainfo=(removed)    
http.sslbackend=(removed)    
diff.astextplain.textconv=astextplain    
filter.lfs.clean=git-lfs clean -- %f    
filter.lfs.smudge=git-lfs smudge -- %f   
filter.lfs.process=git-lfs filter-process    
filter.lfs.required=true    
credential.helper=(removed)    
user.name=(removed)    
user.email=(removed)    
http.sslverify=(removed)    
alias.dt=difftool    
alias.mt=mergetool    
alias.ph=log --graph --oneline --color --decorate    
alias.checkbranches=ls ./*/.git/HEAD | xargs cat    
core.autocrlf=true    
core.editor=vim    
diff.tool=bc3    
difftool.prompt=false    
difftool.bc3.cmd=(removed) $(cygpath -w $LOCAL) $REMOTE    
merge.tool=bc3   
mergetool.prompt=false    
mergetool.keepbackup=false    
mergetool.bc3.cmd=(removed) $(cygpath -w $LOCAL) $REMOTE $BASE $MERGED    
mergetool.bc3.trustexitcode=true    
alias.dt=difftool    
alias.mt=mergetool    
core.repositoryformatversion=0    
core.filemode=false    
core.bare=false    
core.logallrefupdates=true    
core.symlinks=false    
core.ignorecase=true    
remote.origin.url=(removed)    
remote.origin.fetch=(removed)    
branch.master.remote=(removed)    
branch.master.merge=(removed)    
branch.(removed)    
branch.(removed)
branch.(removed)
branch.(removed)
K13
  • 124
  • 9
  • Any chance the batch file is being run as a different user, or one is being edited in admin mode and the other is not? I once edited a file as admin and depending on which user opened the file, it appeared differently. – TTT Jul 28 '20 at 18:44
  • The obvious thing to check, is the batch file committing its changes? Could you show us the batch file? How, exactly, are you verifying it has been changed? Can you show us `git config --list` to check if there's any odd configuration? – Schwern Jul 28 '20 at 18:55
  • Another thought, is the batch file possibly running a different git executable? – Schwern Jul 28 '20 at 18:58
  • @Schwern - that would be pretty funny if the batch script commits the change, and would explain it, except for maybe #7. – TTT Jul 28 '20 at 19:03
  • I know you said assume unchanged didn't help, but did you try resetting the file: https://stackoverflow.com/q/16993082/184546 – TTT Jul 28 '20 at 19:09
  • 1
    Is the batch file making sure to close the file? If not, its changes might not be flushed to disk. Similarly, is there anything unusual about the filesystem? Network drive? Dropbox? – Schwern Jul 28 '20 at 19:13
  • @TTT - No, as I run them both (git status and the batch file) manually, and have tried running both in consoles with Admin rights. And well - no - because a git reset would just remove files from staging/index, and the file is not staged yet - because git status will not register any changes for me to add it :-) – K13 Jul 28 '20 at 23:33
  • @Schwern - Yep, the batch file is definitely not committing anything. Standard filesystem on a windows VM. How can I check if the batch file is closing the file ? I will google this too. – K13 Jul 28 '20 at 23:35
  • @Schwern I will add batch file pseudocode. – K13 Jul 28 '20 at 23:37
  • We don't want pseudocode, @K13, for your specific question. We need to be able to reproduce your issue, and for that we need a [mcve] of the code. That is essentially every part of the code which is used to create, or could potentially modify the content of, your variables, `%HOME%`, `%TARGET_FILE%`, and `%SOURCE_FILE%`. We need to know the variable expansion mode at that point, and know whether that or any of the missing code is nested in code clocks etc. Please [edit your question](https://stackoverflow.com/posts/63140340/edit) to provide sufficient code for us to assist you with it. – Compo Jul 29 '20 at 00:01
  • In addition, if you do not believe that the code you've omitted is responsible for your issue, then your issue is not code related, and doesn't belong on StackOverflow, but on [SuperUser](https://superuser.com/questions/ask) instead. – Compo Jul 29 '20 at 00:03
  • @Compo - Maybe pseudocode was not the right word for me to use. The components of the batch file that do any meangingful work in this context are shown - I have just generalized var names and not included actual file locations. The batch file itself isn't doing anything magical - just attrib, erase, and copy. With the arguments I have added. It is sufficient for a minimally reproducible example if so inclined. – K13 Jul 29 '20 at 00:12
  • @Compo Can you elaborate why it should be on SuperUser ? I see this as at its core, a question/issue with how git status works. I thought that SO was appropriate for a question like that. – K13 Jul 29 '20 at 00:14
  • 1
    I can't say for sure (because I don't "do" Windows) but it seems likely that your batch file is leaving the file size and time-stamps alone so that Git thinks the file hasn't been modified. Git's index stores `stat` data and relies on the fields being changed by things that change the file, so that Git doesn't have to de-compress or re-compress the file if it's really untouched. If this is the case, updating the modification time to "now", after waiting at least 1 second (maybe more on Windows), would fix the problem. – torek Jul 29 '20 at 00:20
  • @torek - Yes, that was my initial thought too. On windows, I should be able to add the /b flag on the copy per one of the answers here https://superuser.com/questions/292630/how-can-i-change-the-timestamp-on-a-file to update the timestamp. However trying this did not work. Maybe I can look into other ways to force the mod time to update. – K13 Jul 29 '20 at 00:29
  • 1
    Try each of these cumulatively: remove pause, remove call gradle, remove erase and use copy /y, add /v to copy. I think torek is on to something. – Schwern Jul 29 '20 at 01:40
  • @K13, how does git status work is a question about git not about a specific issue with your half provided code. – Compo Jul 29 '20 at 11:12
  • @Schwern - Will do. This issue resolves for a time after manually updating the file, so I will try this next time. – K13 Jul 30 '20 at 05:37
  • If you add a short delay after the erase command, can you run git status while the file is gone to make sure that it detects it's missing? After the file reappears with different content, presumably git status will no longer list it. At this point is the timestamp and size different from the original? (I think you said timestamp is not but size should be, correct?) – TTT Aug 03 '20 at 21:35

0 Answers0