0

For reference: My master branch is essentially a dead branch (I haven't visited in months), all deployments are made from my dev2 branch. Checking out to master was an error of natural reflex since my other projects all use master.

For context: I was on a feature branch, I checked out to master and all of my untracked files were automatically updated. I need these files to return to their previous state for my code to be in working order.

Here is a list of my operation in order with their related git notifications:

From a clean working tree, git checkout master

$ git checkout master

Updating files: 100% (59224/59224), done. Switched to branch 'master'

I ran a git status

$ git status

Untracked files: (use "git add ..." to include in what will be committed) 
  .DS_Store 
  .env node_modules/.bin/ 
  etc. 

but note that the list is long and they are node modules and cp resource files.

I ran a git add, and then git stash

$ git add .
$ git stash

Saved working directory and index state WIP on master: c28616b90 fix ht access

Then I did a git status

$ git status 

On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean

Checked out to a working branch called "dev2", which is essentially my master branch

$ git checkout dev2

Updating files: 100% (59224/59224), done. Switched to branch 'dev2'

It appears the untracked files updated on master have followed me to other branches and updated those branches.

Here's a git log

$ git log

commit f45afe47f6c5d4e1e63c71748cd556d9c133fd21 (HEAD -> tyClients)
commit c82fb69f9147082ccdfe6d955be7e4a5508b7f3a (origin/dev2, mobForms, dev2)

The file updates are in my gitignore.

I would like the untracked files to return to their previous state on all branches before this git stash or at their state of my last real commit.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • What version of Git do you have? `git stash` was rewritten in C recently and has some quirks depending on specific Git version. In general this is another problem entirely, but recovering may (or may not) depend on exact Git version. – torek Jan 13 '22 at 09:50
  • I have git version 2.30.1 – Ross Northrup Jan 13 '22 at 12:42
  • _"I checked out to master and all of my untracked files were automatically updated."_ Are you saying that, while on your feature branch, you had files which were untracked, but there were files by those names checked into the mater branch? – J-bob Jan 13 '22 at 23:11

1 Answers1

-1

I was able to retrieve files stashed from master on affected branches by using

git stash apply

This 3-minute video was very helpful on how to use git stash without overcomplicating the concept of git stash. https://www.youtube.com/watch?v=fXGug4itlTk

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • Welcome to Stack Overflow. For a variety of reasons, [link-only answers are discouraged here](https://meta.stackexchange.com/a/8259/248627). Please edit your answer and include the main points directly in your question. See [answer]. – ChrisGPT was on strike Jan 15 '22 at 00:45