Hi folks!!!! I have an issue since I started using Astro (I don't know if it's related) with my repos. I commit as I've always done using git add . => git commit -m 'something' and after a while all my files appeared tracked as deleted and untracked again (see screenshot). I'm very confusing as it has never happened before and I don't change anything about my way to use git. I don't have yet a remote repo for the moment I have a local one. It happened during the Astro Course and again now in my personal project. Do you have any idea??? Thanks in advance
#Repo deletes all files and re-staged them!!!
1 messages · Page 1 of 1 (latest)
Do you still have git branch information and commit history after the files unstage?
And is it all your files in the whole repo or just a subset that show as untracked?
Yes I have the history of all commits when I do git log I have them all (see screenshot) and yes all the files becomes untracked
Let me check is it because I added vscode folder in .gitignore?
that shouldn't be it
the only 2 files that are not untracked
adding something to your .gitignore should only prevent from tracking that thing. This sounds like an issue with your .git directory though.
something may be misconfigured for some reason.
what you might try is to push your project to Github and then make sure it pushed everything you want. Then clone it back to your machine in a different directory, and then move over any untracked files like .env files and so on. Then see if the issue happens again.
by cloning it back it may smooth out any configuration that is wrong.
ok thanks nik I'll try, for the moment it doesn't change anything as everything is here but it's very annoying after commiting (only sometimes) everything as to be added again and commit again. Thanks for your help
yeah you shouldn't have to do that, something isn't right.
ok I stop committing for now and clone what I have
and it specifically shows them as untracked, not just modified?
Yes they as 'U' in my version control
I see that now in your screenshot.
I'm having to remember all the things VS Code shows you, it's been a while for me 😛
as you see only the vscode files are deleted and don't appear as untracked
it's almost like something is moving your files, like the directory name they are sitting in is changing.
which OS are you using?
Mac Sonoma
how deep is the directory structure your files are sitting in?
User/documents/dev/
I've heard of issues if the full path to a file is too long, but yours is definitely not. (and iirc I heard about that happening on Windows)
Yes that’s weird
ok I would push it to GH and clone it again. Also you might check for updates to both Git and VS Code.
Ok thank you so much I’ll let you updated
how frequently is this happening? Every commit, every hour, ???
It depends, it happens twice this weekend and 1 yesterday
Today it didn’t happen!!! For the moment 😉
very, very strange. Keep me updated, I'll be on my mac a lot more than usual the next few days so I'll pay attention also.
if you close and reopen VSC again is that still the case?
I'm sure that there is something woth the vscode folder
what's in the .vscode folder right now?
you said you added that to your .gitignore?
yes
did you also delete it from the git cache? git rm --cached ./.vscode?
no
lemme double check that command before you run it
yeah that's correct, but I wanted to be SURE before I told you to do anything with an rm in it
ok that I run it?
yeah
Do I commit all first?
MAKE SURE you have git at the front of it though. and you don't need to commit anything. What that does is remove the .vscode directory from Git's tracking only. It doesn't remove it from your file system.
right now, you still have that in tracking in Git's internal database, but your editor is also trying to ignore it. Those two disagreeing might be causing your issue.
it might be git rm -r --cached ./.vscode
wait, you need the recursive flag. I edited the command above.
git rm -r --cached ./.vscode
fatal: pathspec './.vscode' did not match any files
it doesn't work
it seems to work at the end the version control is empty and i restart vs code and still empty
if you run git status are you seeing any changes?
nothing to commit, working tree clean
ok, one last test to make sure it's all working, would be to push the repo to GH and make sure all your files are there.
If so, you should be in good shape.
i will a bit later have to go pick up the kids, i'll let you know
thanks so much again
I hope I helped and good luck!
Double check that you don't have multiple .git directories at different levels. Whenever my tracking is messed up, it's because there's conflicting .git folders. It can happen when you clone and initiate new projects. The clone has a git folder and the new project has a git folder.
.git folders are hidden by default, so you don't even see them
You helped me a lot thanks again. It seems to work properly now after pushing to github. I restart VSCode and no more issues. Thanks also @pale halo I've checked my .git folder to be sure there was one. I think it was really the .vscode folder I didn't remove its cache and during the issue there was the only 2 files (in the folder .vcode) that weren't in the untracked list after deletion. I hope it's gonna be fixed for ever now and if not I have some great tips from you. One final question do I have the option to not include the vscode file anyway in my project? Is it good practice?
in order to exclude anything, just add it to your .gitignore before you git add . and git won't ever look for it again. If you want to add it later, remove the entry from your .gitignore and it will show up as untracked.
as for whether or not to track that directory, that's a choice you have to make. For example, having the settings and extensions related to that project would mean you could clone the repo to another machine and it would be set up the same and recommend any missing extensions.
That's strictly VSC related though, which even though it's the de-facto standard, many people use different editors.
so if you wanted something like consistent tab stops, tabs vs spaces, etc. you could also use a .editorconfig file, which pretty much any text editor will respect. And as a bonus, Prettier uses .editorconfig settings as well.
So your format on save that you might have set up would just follow that.
Ok got it!!! I’ve leant so much today 😉. Really appreciate
@idle nymph Hi there!! My issue persist and I become crazy about that. I've deleted a bunch of extensions. I open a project, make a change do my commit and I push to github. Then I make another change and this happen (screenshot of my version control), I also add the screenshot of my git settings in vscode. I really don't know why it happens. I also don't put anymore the vscode folder in .gitignore.
just to be sure if I create a github repo I choose push an existing one and paste:
git remote add origin [email protected]:Canfry/test-git-issue-astrov4.git
git branch -M main
git push -u origin main
??
I wrote you this message and came back to my project and things changed again
Without doing anything
the same version control that acts by itself
the little clock on the version control appears and desappears very often when I change files but I suppose it's normal it's just checking for changes??
it happens when I'm also on the same file without doing anything, like constantly searching for changes
I've also upgraded my git in my system to see if solves the issue but doesn't seem to
This is a very strange problem. When it happens, if you close and reopen your editor does it say the same thing?
Yes it happens like this without doing anything and disappear only when I commit all again
I was thinking that when I create a repo for some projects I omit (because I saw it on a Python course) git branch -M main. And maybe with these projects opened at the same time there is conflict in local git so has to update every time. Maybe it’s stupid but I don’t even know where to look. Now I’m using GitHub CLI to create my repo to see if works properly
start with a brand new directory with no git tracking at all, and then do as follows:
git init to initialize the repo
touch .gitignore if there isn't one already
add some things to the gitignore
git add . to add the rest to tracking
git commit -m "<your message here>" whenever you commit.
add the remote per gh instructions
let me know if you have the problem again.
what I'm afraid of is that your file system is corrupted, which could be causing this issue. I don't know how to approach resolving that if that's the case.
Thank you so much @idle nymph this is what I’ve done using gh for the moment no errors I’ll let you know. 🤞🏻🤞🏻🤞🏻
been following this thread ... such a strange unexpected phenomenon 😦
i hope you get it sorted away amigo.
Gracias amigo, I hope too!!!
@vestal torrent @idle nymph @pale halo I'm still having this issue over and over again even with fresh new project. I do git add * => git commit -m 'my message' => git push. I do something else and in my version control all my files are deleted and untracked again. I become crazy
i copy/paste your initial post into chatgpt, this is what it said:
It sounds like you're experiencing an issue where files in your local Git repository are showing up as deleted and untracked, even though you haven't intentionally deleted them. This situation can be confusing, but there are a few potential causes and solutions to consider:
1. **Accidental Deletion or Git Reset**: Ensure that the files were not accidentally deleted or that a `git reset` command wasn't executed which could revert the state of your repository.
2. **Case Sensitivity Issues**: Sometimes, case sensitivity issues can cause this problem, especially if you're using a filesystem that is case-insensitive (like on Windows or macOS). Git might be tracking a file in a different case than the filesystem.
3. **.gitignore Configuration**: Check your `.gitignore` file. It's possible that a rule in this file is causing Git to ignore (and therefore see as untracked) files that were previously committed.
4. **File Permissions Changes**: Git can sometimes mark files as changed if their permissions have been modified. This might not be the case here since they are appearing as deleted, but it's worth checking.
5. **Corrupted Git Repository**: In rare cases, the Git repository itself might become corrupted. This could be due to a variety of reasons like disk errors, abrupt system shutdowns, or bugs.
6. **Branch Issues**: Ensure you are on the correct branch. Sometimes, if you accidentally switch branches, it can appear as though files have been deleted.
To troubleshoot this issue, you can try the following steps:
- **Check Current Status**: Use `git status` to see the current status of your repository. This will show you which files are tracked, modified, deleted, or untracked.
- **Review Git Logs**: Check your Git logs (`git log`) to see the history of commits. This might give you a clue as to when the files were deleted or modified.
- **Check Other Branches**: If you have multiple branches, ensure you're on the correct branch. Use `git branch` to see all branches and `git checkout [branch_name]` to switch branches.
- **Restore Deleted Files**: If the files were accidentally deleted, you can restore them from a previous commit. Use `git checkout HEAD^ -- [file_name]` to restore a file from the last commit.
- **Clone Repository Again**: If all else fails and you have a remote repository, you might consider cloning the repository again in a new directory to see if the issue persists.
Since you mentioned this happened during your Astro Course and again in a personal project, it would be helpful to see if there's a common pattern or action causing this issue.
If you have a screenshot or more specific details about the messages or errors you're seeing, that could also help in diagnosing the problem more accurately.
one thing i am wondering is - if you have another terminal application, does the same thing happen in there as well?
not sure how or IF this would only happen when using the terminal in VS Code.
Thanks for your reply!!! What I can see is, yes it happens with vs code even if I change terminal to commit when I go back to vs code I see the version control with all files untracked. It seems that VsCode is causing this. It’s time to change to nvim 🤣🤣🤣🤣
I’m testing it by the way and I like it have a long way before mastering it
Don't know if this applies at all, but I use git add . and not the * character.
and fwiw, I'm using nvim for JS/ TS dev including integration for React and Svelte and it's legitimately awesome.
It’s the same in both case
I can't remember, do you have any git related extensions for VSC running?
🤔 yeah this one is tough. Maybe try the same repos on a different machine with synced VSC settings and extensions? That would allow you to rule out your machine OR pinpoint that it is the machine.
Yes for sure. I’ll try it and try using nvim for the project to see if it works correctly
Neovim will take some tweaking to get it just how you want it. Have you already got a running configuration set up for JS/ TS?
Yes I took the kickstart
I manage to add another color scheme so I see a little bit how it works
Lua seems a good language
once i got past all the null_* errors, mine has been pretty nice to work with.
if you try it and have other questions, I'm glad to help, but I'll be away from my desk and Discord a lot for the next few weeks from the way things look. @deep fog and @rigid ocean are also nvim users, and you can also hop into ThePrimeagen's discord server and the #vim channel is very active and extremely helpful also.
Lua is also a very simple language, just a few quirks overall.
Amazing thank you!!! 🙏
And of cource @vestal torrent is a resource, assuming they are willing 😉
even got colors working.
Nice
Looks like colors and tailwind working together, I'd like to get that going myself.
But I don’t have it working for Astro files
I believe Astro has a language server.
Just have to add Astro to the list of the languages???
i just can't get prettier working with astro.
driving me crazy.
yes, Mason > astro-language-server
I can't remember off hand if kickstart uses mason-lspconfig. If so you should get a "default" connection to the astro server if you add it to the "ensure_installed" list.
Thanks will check that out
It’s amazing how we get so excited when adding new things in vim 🤣🤣
🤣
to me it's like driving a car and you keep finding new top gears.
little things that smooth out more and more pieces of the experience.
Yes totally agree and I’m just starting I think I will love it more and more
Which terminal are you using with vim?
here's my current config with matched tmux and nvim themes. I also have a custom lualine component that shows which LSP servers are attached to a buffer.
I'm using Wezterm on both my Windows and Mac machines.
Wow that’s amazing
here is mine
feel free to explore my config and steal whatever you want. It's all public. https://github.com/nikfp/nvim-config
thanks
I like that look a lot, tokyonight?
🤣 yes!!!
hey glad to have you in the club 😎
I wanted catppuccin but wasn't able to make it work. I like this one anyway
im gonna need that link/invite buddy!
for primeagan server 👍
in particular, the #vim channel will be very helpful, but there are ton of channels and everyone is very friendly. I'd stay away from #dev-null and #open-floor-plan, those are the dedicated dumpster fires for s**tposting.
We should organize a video meeting to share our experiences with vim can be nice
Amy did a show with Josh Medeski on compressed.fm that was about a terminal based workflow, and vim was a part of that. They have a youtube stream up.
Great!! We should make our own. A good way to meet each others
DISCORDJoin the Learn Build Teach Discord Server 💬 - https://discord.gg/vM2bagU**STAY IN TOUCH 👋**Newsletter 🗞 - https://www.jamesqquick.com/newslette...
I agree, one of these days we should.
now about that git issue you have, if you work just in nvim do you have it still?
For the moment no but it doesn’t happen all the time that’s the weird part
I will let you posted
so after re-reading your post - does this happen in all your git repos?
For the last couple of months yes!!! I didn’t try all my repos but it also happened with Python projects
that's just terrible 😦
i can't imagine what the issue that is causing this error.
Yes from a day to another and can’t remember to have changed something big or extensions!!! Nothings!!! It’s frustrating
what operating system are you using? can you locate the git binary? there has to be a process reverting your commits, so starting from the git binary and seeing what can call it is the only way you'll really root it out.
I'm using Mac
let me check how to get git binary
git is installed in usr/local/bin
I have the alias in usr/local/bin and the executable one in usr/bin
maybe is the issue?
Can i uninstall git and re-install?
how did you install it to begin with? Curl/ brew / ????
I don’t remember really but it was way before the date it puts on the screenshots it was 2 or 3 years ago
I think downloading from the website
3 or 4 years better
you might need to update Git as well.
extreme times call for extreme measures, create a greedy shell script that logs every time git is invoked.
#!/bin/bash
echo "$(date): GIT Command Invoked: $@" >> ~/git-commands.log
/usr/bin/git "$@"
we know that git can't do anything unless that binary is invoked, so logging system wide calls will eventually filter out the action you don't expect.
even if you reinstall git, it's being called by something unexpected, so the behavior will persist.
Do I have to follow the instruction ??
only the last line displays what it is on the screenshot
git version 2.43.0
I'm thinking seeing the screenshot that might be the CW which stands for code whisperer the new Fig. It can be related
that's just an example approach using a bash script. the idea is to write your own command line script that would replace the git alias, so whenever the system invokes git, it actually invokes your script and you log out each instance the system uses git, that will give you a definitive answer to the behavior.
if you're not familiar with bash scripts yet, that's OK. It's a file that ends in .sh and can be executed by your shell. it's handy for automating system stuff and in this case, intercepting system behavior to log out what's going on.
Yes not so familiar with this kind of things yet. Thanks anyway for your amazing help
i think i came up with a successful git-logger.sh script for you.
just did some testing and it works for me, although i am on Arch linux, it may be different for you.
save this as ~/git-logger.sh and chmod +x ~/git-logger.sh
i saved mine in my user root ~/
then create an alias in either bashrc or zshrc. don't forget to "source" the file.
alias git='~/git-logger.sh'
i did a little testing, attached screen grab to show ya how it logs.
this is the script
#!/bin/bash
# Get the current working directory
current_dir=$(pwd)
# Log the command along with the timestamp and working directory
echo "--------------------------------------------------" >>~/git-commands.log
echo "$(date): GIT Command Invoked in directory $current_dir: $@" >>~/git-commands.log
# Run the git command and capture its output and error
# output=$(/usr/bin/git "$@" 2>&1)
# THIS IS THE PATH YOU POSTED ABOVE!
output=$(/usr/local/bin/git "$@" 2>&1)
# Log the output of the git command
echo "Output of the command:" >>~/git-commands.log
echo "$output" >>~/git-commands.log
echo "--------------------------------------------------" >>~/git-commands.log
i just took what @pale halo posted above, and pasted into ChatGPT. several iterations/tests later, this is working for me 👍
I'm crossing my fingers that this logs the culprit for you.
WOW!! That's amazing thank you. I have little questions though. I created the git-loggoer.sh file in my root directory. I created the alias. I created a file git-command.log in my project directory. I started using git status but I have zsh: permission denied for /Users/christopheanfry/git-logger.sh
Do i have to do a kind of sudo somewhere?
Also what do you mean by "don't forget to "source" the file"and to also save it as chmod +x ~/git-logger.sh?
i doubt there is a need to create the git-command.log file, as mine was created automatically.
chmod +x git-logger.sh
i gotta head out, pick up the kiddos.
let us know later how this works out for you?
It's kind of work
did you completely restart your terminal, or run source ~/.zshrc?
only the git status appears
I just did it right now
the other commands don't work
it's kind of work
just created a simple comment and committed it and again all files deleted in source control and untracked again
I try git log and git git status but doesn't show in the git-commands.log file
look what happen just after I commit 10165 deletions
This is the log after the little change that i did to try it out. It shows that everything is untracked
It was cut on the right
you might try completely uninstalling Git, then reinstalling.
also you can delete the local repos and then clone them again after you reinstall.
https://git-scm.com/download/mac
shows here, the latet version is 2.33.0.
Yes I will do that!! Thank you so much @vestal torrent @idle nymph @pale halo for your time into this I really appreciate.
you betcha bud.
hope you get this confusing issue resolved soon! 👍
After a little bit of search I've found that I have git installed with brew which puts git in "usr/bin" and I also have installed git from the webpage which puts git in "usr/local/bin", which is the one mentioned when I type "which git". I've deleted the brew one. I've deleted my project and clone the remote in empty folder. Things look great for the moment as I didn't open VsCode yet as I'm scared of it 🤣 . With vim and my terminal it works great. I'm always checking with git status and looks clean
:q 🤣 you'll thank me later!
heads up, if you don't know what a PATH variable is, you're standing right on top of it now. The PATH environment variable is a list of all the locations your terminal will attempt to make a call to a named binary or alias. echo $PATH will show them all, your terminal goes through them in order from left to right. It's a global environment variable accessible on your command line inside your shell.
Thanks for your explanations, having this kind of big issues we learn so much thanks to you guys!! 🙏
Hope you get it fixed, that's why we're here. Community is important.
It seems to be fixed now I still cross my finger but with vim and my terminal everything looks fine for the moment!! I'm gonna stay like this for a moment and we will try to open Vscode later. If the issue comes back I'll know it comes form vscode!!
It happened again
Fun fact that in Vercel it seems that my repo is clones automatically
see screenshots at the same time
Maybe it's normal that vercel clones the repo?
In the git-commands.log file there is nothing since january 8th
Vercel should be watching for a push and then cloning and building the repo so it can redeploy.
I get it!!! 🙏
So on an existing repo, previously tracked files become untracked the moment you commit?
Is that correct? At what point does the git repo untrack a file?
your machine is haunted and needs an exorcism
When I just press enter after git commit
What does git status show before you commit?
After shows my actual changes and as you see in the screenshot after it shows clean tree
how about before?
Before shows my actual changes nothing weird
so 1. git status is normal, then 2. git add . is normal, but 3. git commit -m, all files are unstaged and untracked, become restaged and retracked in the git log?
wow, today I learned about git hooks. I did not know git had internal lifecycle hooks. https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks, there could be an errant hook doing something. By default, none of the hooks should be active in the .git/hooks directory within your project directory. But who knows, can you look in there?
Normally they shouldn't be affected anything configured like this. I should run specific command to make them run
Learning also a lot about those hooks. Very powerful and customizable
that looks like what I have as well, I had no idea about them till just now
What in the what is causing this errant behavior!?!
what's weird is that they say that Client-side hooks (the one that affect me) are not copied when cloning a repo. I coned a repo for this project as I started from scratch
yes that's the fight it seems
I'm not great at reading git logs, but that's the last place to really dig into
unless there's some crazy file permission thing happening at the OS level that is preventing git from doing what it ought to.
yes seems a big mess internaly. I'll see what I can do thanks again for your help and time!!!
does this happen ONLY in this one repo, or ALL repos?
For the moment it’s this one because I’m working only in this one as I have to be able to deploy before sunday for the hackathon. The only other repo that I use is the nvim config one and no issue with it. Maybe it’s a problem of my folder. Will test next week creating a new folder for my projects.
was discussing earlier git hooks ?
🤔
this happens ONLY in ONEproject?
none others?
you cloned the project/repo from someone elses repo?
that may very well be the problem.
a while back, i wrote a custom post-commit hook for a project that would echo that commit hash to a file after deployment locally.
so i would them (later) see what commit was the "LIVE" one that deployed successfully.
maybe there's a hook/script hiding in there somewhere that's the freaking culprit? 🤔
It happened in several projects. For now I’m trying to move the folder with all my projects outside of the iCloud and keep them locally. See if it changes something
whoa.
that's a frightening thought!!!
could iCloud be causing this?
I don’t know I’m out of ideas I’m just trying everything that I can to see if things change
I’m gonna also try to create new projects inside a brand new folder to see what happens
I think this might be something. I use Onedrive extensivly for work and one of it's "features" is that it will occasionally re-sync a file and mark it as updated. That would trigger Git.
Have all the projects this has been a problem with been inside your managed Icloud directory?
yes because my main folder for all my projects is in the icloud directory
the problem is that when I try to move the "dev" folder (with all my projects) outside the icloud Finder is stuck on "Preparing copy folder to new location"
But i'm pretty sure there is something going with the sync. From now on I will create the projects in a local folder to see what happen
just start with the project you need now and git clone from GH back to the local directory.
👍
As I have to submit the project before sunday for the moment I don't touch anything as the project is done and deployed
trying to move that directory will be moving tens / hundreds of thousands of files. That will be slow at best.
I will check later on
Yes you're right maybe little by little
iCloud or watched folders would definitely mess with git
iCloud officially says not to backup app directory folders like .git
*Avoid storing app folders, libraries, .tmp, .vmdk, .vmware, .vbox, .vm, and .pvm files in iCloud Drive.```
https://support.apple.com/en-us/HT201104
Apple Support
iCloud Drive lets you securely access all of your documents from your iPhone, iPad, iPod touch, Mac, and Windows PC.
Might want to consider a different back-up workflow for your source code, I consider the remote repo as a backup, but if you wanted a local backup, you could probably consider something else.
Yes it was the last thought on what was causing this. Thank you so much to stay alert on this matter. I’m moving all my projects into a local directory will not do the same mistake again. As you said GitHub is already a backup so no need the iCloud. If I really want an extra backup I will use an external disk. Thanks again @pale halo really appreciate
Things like this help us all, and I'll know to check for watched folders next time someone has git issues. Git is weirdly mysterious and straightforward at the same time. I'm actually fascinated by the fact that as a tool, it became de facto so quickly and hasn't seen any other competition at all.
Yes git is very interesting and mysterious as you said. I think I’ve learnt a lot of things like git hooks and its compatibility with iCloud. You’re right no competition at all for git in this world full of new tools or languages or frameworks…Maybe it’s our opportunity 🤣🤣🤣
How would you compete with Git?
I can't think of anything that is worth changing. It's complex, but the core mechanics are simple, and it's scriptable within larger shell scripts meaning it's easy to build abstractions on top of it.
That’s the billion dollar question. Always worth asking.