0

I committed multiple files, and now when i type: git status: I got message: (use "git push" to publish your local commits).

How can I return those files into working memory?

My goal is to return all files into working memory, and not lose any changes which I committed?

Predrag Davidovic
  • 1,411
  • 1
  • 17
  • 20
  • Can you clarify what you mean by `working memory`. There is [git restore](https://git-scm.com/docs/git-restore) for restoring files into previous state. – kapsiR Mar 16 '21 at 08:32
  • I wanted files which I committed previously to return into my vs code like before commit. With all changes which I already created. – Predrag Davidovic Mar 16 '21 at 08:37
  • Does this answer your question? [What's the difference between git reset --mixed, --soft, and --hard?](https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard) – kapsiR Mar 16 '21 at 09:49
  • It seems like your phrase "working memory" is what Git means by its phrase "working tree". – torek Mar 16 '21 at 16:47

3 Answers3

1

I solved it with: git reset --mixed HEAD~1

Predrag Davidovic
  • 1,411
  • 1
  • 17
  • 20
1

It's good to know that when you initial a git repository in your local machine it has three different areas as follow:
1-Working Area
2-Staging Area (Index)
3-Repository (local)
when you use git add {file name(s) or patterns or .} you send files from the working area to the staging area and when you create a git commit in fact you send the files from the staging area into the repository.
here is some useful command to use:

-Removing files:
git rm {file name} #Removes from the working directory and staging area
git rm --cached {file name} #Removes from staging area only

-Renaming or moving files:
git mv {source file name} {destination file name}

-Viewing the staged/unstaged changes:
git diff #Shows unstaged changes
git diff --staged #Shows staged changes
git diff --cached #Same as the above

-Viewing the history:
git log #Full history
git log --oneline #Summary
git log --reverse #Lists the commits from the oldest to the newest

-Viewing a commit:
git show {commit id} #Shows the given commit
git show HEAD #Shows the last commit
git show HEAD~2 #Two steps before the last commit
git show HEAD:{file name} #Shows the version of file.js stored in the last commit

-Unstaging files (undoing git add)
git restore --staged {file name} #Copies the last version of file.js from repo to index

-Discarding local changes:
git restore {file name} # Copies file.js from index to working directory
git restore {file name(s)} #Restores multiple files in working directory
git restore . #Discards all local changes (except untracked files)
git clean -fd #Removes all untracked files

your answer:
To restoring an earlier version of a file
git restore --source=HEAD~1 {file name}

Mohsen Sabbaghi
  • 148
  • 1
  • 12
0

git reset is probably what you are looking for.

The reset command has several options:

  • --hard discard any changes
  • --soft keeps changes on your staging area
  • --mixed keep some changes on staging area and some in working directory

There are even more parameters. Refer to documentation for details.

Sparkofska
  • 1,280
  • 2
  • 11
  • 34