#Repo deletes all files and re-staged them!!!

1 messages · Page 1 of 1 (latest)

terse tree
#

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

idle nymph
#

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?

terse tree
#

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?

idle nymph
#

that shouldn't be it

terse tree
#

the only 2 files that are not untracked

idle nymph
#

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.

terse tree
#

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

idle nymph
#

yeah you shouldn't have to do that, something isn't right.

terse tree
#

ok I stop committing for now and clone what I have

idle nymph
#

and it specifically shows them as untracked, not just modified?

terse tree
#

Yes they as 'U' in my version control

idle nymph
#

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 😛

terse tree
#

as you see only the vscode files are deleted and don't appear as untracked

idle nymph
#

it's almost like something is moving your files, like the directory name they are sitting in is changing.

#

which OS are you using?

terse tree
#

Mac Sonoma

idle nymph
#

how deep is the directory structure your files are sitting in?

terse tree
#

User/documents/dev/

idle nymph
#

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)

terse tree
#

Yes that’s weird

idle nymph
#

ok I would push it to GH and clone it again. Also you might check for updates to both Git and VS Code.

terse tree
#

Ok thank you so much I’ll let you updated

idle nymph
#

how frequently is this happening? Every commit, every hour, ???

terse tree
#

It depends, it happens twice this weekend and 1 yesterday

#

Today it didn’t happen!!! For the moment 😉

idle nymph
#

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.

terse tree
#

Ok 👌🙏

#

it just happened again when I restart vscode

idle nymph
#

if you close and reopen VSC again is that still the case?

terse tree
#

I'm sure that there is something woth the vscode folder

idle nymph
#

what's in the .vscode folder right now?

terse tree
#

maybe an extension

#

extensions.json and launch.json

idle nymph
#

you said you added that to your .gitignore?

terse tree
#

yes

idle nymph
#

did you also delete it from the git cache? git rm --cached ./.vscode?

terse tree
#

no

idle nymph
#

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

terse tree
#

ok that I run it?

idle nymph
#

yeah

terse tree
#

Do I commit all first?

idle nymph
#

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.

terse tree
#

fatal: pathspec './.vscode' did not match any files

#

I have to commit first it seems

idle nymph
#

it might be git rm -r --cached ./.vscode

#

wait, you need the recursive flag. I edited the command above.

terse tree
#

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

idle nymph
#

if you run git status are you seeing any changes?

terse tree
#

nothing to commit, working tree clean

idle nymph
#

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.

terse tree
#

i will a bit later have to go pick up the kids, i'll let you know

#

thanks so much again

idle nymph
#

I hope I helped and good luck!

pale halo
#

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

terse tree
# idle nymph I hope I helped and good luck!

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?

idle nymph
#

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.

terse tree
#

Ok got it!!! I’ve leant so much today 😉. Really appreciate

terse tree
#

@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

idle nymph
#

This is a very strange problem. When it happens, if you close and reopen your editor does it say the same thing?

terse tree
#

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

idle nymph
#

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.

terse tree
#

Thank you so much @idle nymph this is what I’ve done using gh for the moment no errors I’ll let you know. 🤞🏻🤞🏻🤞🏻

vestal torrent
#

been following this thread ... such a strange unexpected phenomenon 😦

i hope you get it sorted away amigo.

terse tree
#

@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

vestal torrent
# terse tree Hi folks!!!! I have an issue since I started using Astro (I don't know if it's r...

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.

terse tree
#

I’m testing it by the way and I like it have a long way before mastering it

idle nymph
idle nymph
idle nymph
#

I can't remember, do you have any git related extensions for VSC running?

terse tree
#

I don’t think so

#

I only have copilot

idle nymph
#

🤔 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.

terse tree
idle nymph
#

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?

terse tree
#

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

vestal torrent
idle nymph
#

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.

idle nymph
#

And of cource @vestal torrent is a resource, assuming they are willing 😉

vestal torrent
#

even got colors working.

terse tree
#

Nice

idle nymph
#

Looks like colors and tailwind working together, I'd like to get that going myself.

vestal torrent
terse tree
idle nymph
terse tree
#

Just have to add Astro to the list of the languages???

vestal torrent
#

i just can't get prettier working with astro.
driving me crazy.

yes, Mason > astro-language-server

idle nymph
#

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.

terse tree
#

Thanks will check that out

#

It’s amazing how we get so excited when adding new things in vim 🤣🤣

vestal torrent
#

🤣

idle nymph
#

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.

terse tree
#

Yes totally agree and I’m just starting I think I will love it more and more

#

Which terminal are you using with vim?

idle nymph
#

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.

idle nymph
terse tree
#

here is mine

idle nymph
terse tree
#

thanks

idle nymph
terse tree
#

🤣 yes!!!

deep fog
#

hey glad to have you in the club 😎

terse tree
#

I wanted catppuccin but wasn't able to make it work. I like this one anyway

vestal torrent
#

for primeagan server 👍

idle nymph
#

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.

terse tree
#

We should organize a video meeting to share our experiences with vim can be nice

idle nymph
#

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.

terse tree
#

Great!! We should make our own. A good way to meet each others

idle nymph
#

now about that git issue you have, if you work just in nvim do you have it still?

terse tree
#

For the moment no but it doesn’t happen all the time that’s the weird part

#

I will let you posted

vestal torrent
terse tree
#

For the last couple of months yes!!! I didn’t try all my repos but it also happened with Python projects

vestal torrent
#

i can't imagine what the issue that is causing this error.

terse tree
pale halo
terse tree
#

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?

idle nymph
#

how did you install it to begin with? Curl/ brew / ????

terse tree
#

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

idle nymph
#

you might need to update Git as well.

pale halo
#

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.

terse tree
#

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

pale halo
# terse tree Do I have to follow the instruction ??

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.

terse tree
vestal torrent
#

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 👍

pale halo
#

I'm crossing my fingers that this logs the culprit for you.

terse tree
#

Do i have to do a kind of sudo somewhere?

vestal torrent
#

no sudo.

#

as a "safe / best practice", dont run ANY script as sudo.

terse tree
#

Also what do you mean by "don't forget to "source" the file"and to also save it as chmod +x ~/git-logger.sh?

vestal torrent
#

i doubt there is a need to create the git-command.log file, as mine was created automatically.

terse tree
#

ah ok

#

but I still have permission denied when doing git status

vestal torrent
#

chmod +x git-logger.sh

#

i gotta head out, pick up the kiddos.
let us know later how this works out for you?

terse tree
#

It's kind of work

idle nymph
terse tree
#

only the git status appears

terse tree
#

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

idle nymph
#

you might try completely uninstalling Git, then reinstalling.

#

also you can delete the local repos and then clone them again after you reinstall.

vestal torrent
terse tree
vestal torrent
terse tree
#

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

vestal torrent
terse tree
#

Yes thanks so much guys

pale halo
# terse tree After a little bit of search I've found that I have git installed with brew whic...

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.

terse tree
pale halo
terse tree
terse tree
#

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

idle nymph
#

Vercel should be watching for a push and then cloning and building the repo so it can redeploy.

pale halo
#

Is that correct? At what point does the git repo untrack a file?

#

your machine is haunted and needs an exorcism

terse tree
pale halo
#

What does git status show before you commit?

terse tree
#

After shows my actual changes and as you see in the screenshot after it shows clean tree

pale halo
#

how about before?

terse tree
#

Before shows my actual changes nothing weird

pale halo
#

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?

terse tree
#

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

pale halo
#

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!?!

terse tree
#

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

terse tree
pale halo
#

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.

terse tree
#

yes seems a big mess internaly. I'll see what I can do thanks again for your help and time!!!

vestal torrent
#

does this happen ONLY in this one repo, or ALL repos?

terse tree
#

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.

vestal torrent
#

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? 🤔

terse tree
vestal torrent
terse tree
#

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

idle nymph
#

Have all the projects this has been a problem with been inside your managed Icloud directory?

terse tree
#

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

idle nymph
#

just start with the project you need now and git clone from GH back to the local directory.

terse tree
#

👍

#

As I have to submit the project before sunday for the moment I don't touch anything as the project is done and deployed

idle nymph
#

trying to move that directory will be moving tens / hundreds of thousands of files. That will be slow at best.

terse tree
#

I will check later on

terse tree
pale halo
#

iCloud or watched folders would definitely mess with git

pale halo
#

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
#

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.

terse tree
pale halo
#

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.

terse tree
idle nymph
#

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.

pale halo