git overwrote and mixed up my files

Before hearing of git I was doing a manual version control. Basiclly I would copy a full directory with my code files in it and give it a new name like “Project 1.2 version with that new feature”. Then I installed git and created a local repository with Atom. There were 190 unstaged changes and I was like “What no I don’t want to change my files” so I clicked “discard all” and this deleted all my files. So I used undo last discard and it restored them. Except that it restored ALL the files with the same name from one identical file, of course, an old one. So now ALL my files are the same inside all the 1.x versions. This is catastrophic my research was erased, I don’t know what to do. I though it could only change your files when using commit, which I never did since I never even logged in. I was trying to secure my work and instead it brought me back months ago !

EDIT: Clearer explanation

My project directory looked like this:

> My Project

    > Module 1.1

         - main.jl 

         - morecode.jl

    > Module 1.2

         - main.jl 

         - morecode.jl

etc.

I would accumulate versions by duplicating the “Module” directory. So exactly what I did was (in Atom):

  1. I selected the “My Project file”, went to the git tab and clicked _create repository. _This added a .git directory in My Project.

  2. 190 Unstaged changes appeared in the git tab. I clicked discard all changes(i.e. the stupid thing to do). This deleted all the .jl files in all my Module directories. 

  3. I clicked on undo last discard and this restored them.

But this did not restore them as they used to be. All the files “morecode.jl” (e.g.) are now identical and it somehow selected a random one among all the existing ones in the project.

I’m on windows, I only used atom to do the git operations (not bash).

Please I’m desperate for a solution.

1 Like

I don’t quite understand how Git had any idea about the “old” version if you’d never used Git on this before.

Please try to list every step you did from the beginning one line at a time, the more you break it down the easier it will be for us to help you.

  1. Step 1…
  2. Step 2…

etc, you get the idea, as I say the more detailed you list these steps the easier it will be for others to understand.

Also tell us what operating system you’re using, what other tools etc etc.

1 Like

My project directory looked like this:

> My Project

    > Module 1.1

         - main.jl 

         - morecode.jl

    > Module 1.2

         - main.jl 

         - morecode.jl

etc.

I would accumulate versions by duplicating the “Module” directory. So exactly what I did was (in Atom):

  1. I selected the “My Project file”, went to the git tab and clicked _create repository. _This added a .git directory in My Project.

  2. 190 Unstaged changes appeared in the git tab. I clicked discard all changes(i.e. the stupid thing to do). This deleted all the .jl files in all my Module directories. 

  3. I clicked on undo last discard and this restored them.

But this did not restore them as they used to be. All the files “morecode.jl” (e.g.) are now identical and it somehow selected a random one among all the existing ones in the project.

I’m on windows, I only used atom to do the git operations (not bash).

1 Like

Also, git stash pop returns “no stash entry found”

1 Like

First backup that repo (“My Project” older) immediately and ZIP the backup somewhere safe.

The grab SmartGit and install that, this is a powerful GUI for Git and it makes certain things easier to see or do.

Once you’ve done that, in SmartGit on the left menu use “Repository” then click “Add or Create” and add navigate to your repo folder.

Come back when you’ve done that. I don’t know if I can resolve the problem but we can try.

1 Like

Okay this is done. My project is opened in SmartGit. Here’s a screencap.

Thank you for trying to help.

1 Like

Hi,

OK so Git sees all the files that are in the repo as new, that is not yet present in Git’s history database.

Ordinarly you’d simply doa ctrl-A click “Stage” and then “Commit” that will create a commit which records the state of all those files and the main window would appear empty (the main window shows changed or new or removed files - it doesn’t show unchanged files).

Click on “Log” near the top right, that will show us all history so far…

But are you saying the files (e.g. A3C_main.jl) are somehow not what you expect? thay are “older” versions?

You can double-click any file to see it’s contents by the way.

Let me know…

1 Like

Clicking on Log pops a window saying “The repository is empty. It’s not possible to perform the requested operation on an empty repository”. That doesn’t sound good.

No, they are not an older version per say. See, there are five “A3C_main.jl” files. Their contents were all differents before. After the undo I found that the five ones became identical. One of them hasn’t changed (I don’t know which one), and the others became clones of it. Some files have unique names and these were restored correctly for example. So my guess is that it selected a random (maybe because of a hashing) “A3C_main.jl” and restored it to all the places where a “A3C_main.jl” was. 

1 Like

@henrideh wrote:

Clicking on Log pops a window saying “The repository is empty. It’s not possible to perform the requested operation on an empty repository”. That doesn’t sound good.

 

No, they are not an older version per say. See, there are five “A3C_main.jl” files. Their contents were all differents before. After the undo I found that the five ones became identical. One of them hasn’t changed (I don’t know which one), and the others became clones of it. Some files have unique names and these were restored correctly for example. So my guess is that it selected a random (maybe because of a hashing) “A3C_main.jl” and restored it to all the places where a “A3C_main.jl” was. 

Actually it will be empty (empty means -> no commits have yet been created).

Ordinarily you’d create a new empty repo, then you add your folder to it then you’d select all files, stage them and then do a commit.

That will create the first commit, the file window (in SmartGit) would then clear and look empty.

It will look empty because until a file gets changed (relative to what was last commited) it doesn’t appear.

“Untracked” simply means “This file has no history, no trace of it exists in the history” now in your case there is no (yet) history because nothing has (yet) been commited.

When you did that first “discard” by mistake Git thought “Oh, all these changes (new files) are not wanted, the user doesn’t want them” and so it will have deleted all the files.

I actually think that Git should not allow this on an empty repository because that is a special case and almost certainly an error by the user.

You should Ctrl-A, stage and commit right now with a message like “Initial commit of all files” or something, at least then there current state will be safe.

I’ve never used “undo last discard” so unfortunately not entirely sure how it would behave.

In fact “discard” isn’t usually what you do for an untracked file, you’d do a “delete” so I’m not sure what actually happened here.

In SmartGit you’d have to use “delete” and then when you do it shows this:

image.png

If you choose “Move to Trash” it will put in the Windows recycle bin.

I strongly recommend you do all Git activity in SmartGit going forward, once uou get tha hang of it it’ll be slick, fast and very safe.

I’m not familiar with Atom or it’s Git support.

1 Like

Well, thank you for trying. I made my peace with the fact that I’ll have to redo everything. If you’re intersted, I made a Minimal Working Example in this thread to reproduce the mistake I made. It looks like a bug when you break it down with this simple case. 

1 Like