简体   繁体   中英

GIT: git checkout .DS_Store error: “error: pathspec '.DS_Store' did not match any file(s) known to git.”

I'm trying to remove the changes from this file .DS_Store. using git checkout but I'm getting this error:

git checkout .DS_Store 
error: pathspec '.DS_Store' did not match any file(s) known to git.

When I do git status I get:

git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .DS_Store

Any of you knows how checkout this file ? or if I'm doing something wrong at the moment of the checkout?

I'll really appreciate your help.

You can do git reset or, add the .DS_Store file in .gitignore file.

.DS_store is a auto generated file for MacOS.

$ git add .
$ git reset --hard HEAD


# Or, add '.DS_store' in .gitignore file
$ nano .gitignore

# Now add '.DS_store' at the end of the '.gitignore' file 

Alternate : one of the alternate way to clean Untracked files is -

$ git clean -df                           
# -d remove untracked directories in addition to untracked files, -f (force)

GIT has excellent support for each command.

git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

.DS_Store

Please refer the message, it clearly stating that the file .DS_Store is untracked and if you want the file to be tracked under GIT then use the following command

$ git add .DS_Store

Please refer the following image for the file status lifecycle in GIT.

在此处输入图片说明

For more details refer Git Basics - Recording Changes to the Repository

Checkout

Since the GIT not tracking the file, you cannot checkout the file. The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches. Checking out a file lets you see an old version of that particular file, leaving the rest of your working directory untouched

More on git checkout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM