Minimalist tutorial for .DS_Store files on git Mac

What is .DS_Store?

Mac users may notice that the system often automatically generates a hidden .DS_Store file in each directory. .DS_Store (English full name Desktop Services Store) is a hidden file created by Apple's Mac OS X operating system. Its purpose is to store the custom attributes of the directory, such as the location of the icons of the files or the selection of the background color. It is equivalent to desktop.ini under Windows.

Delete .DS_Store

If there is no automatically generated .DS_Store file in your project, just add .DS_Store directly to the .gitignore file. If the .DS_Store file already exists in your project, you need to delete it from the project first, and then add it to .gitignore.

As follows:
delete all .DS_Store in the project. This will skip the .DS_Store
1.find that is not in the project . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Add .DS_Store to .gitignore
2.echo .DS_Store >> ~/. gitignore
update project
3.git add --all
4.git commit -m'.DS_Store banished!'
If you only need to delete the .DS_Store on the disk, you can use the following command to delete all of the current directory and its subdirectories. DS_Store file:

find . -name ‘*.DS_Store’ -type f -delete

Disable or enable automatic generation

禁止.DS_store生成:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

Restore .DS_store generation: Restore .DS_store generation:
defaults delete com.apple.desktopservices DSDontWriteNetworkStores

Under the Apple Mac OS X operating system, there are many ways to set whether to display hidden files. The simplest one is to enter commands in the Mac terminal. The command to show/hide Mac hidden files is as follows (note the spaces and is case sensitive):
Command to show hidden Mac files: defaults write com.apple.finder AppleShowAllFiles -bool true
Command to hide hidden Mac files: defaults write com.apple. finder AppleShowAllFiles -bool false
or
the command to show hidden Mac files: defaults write com.apple.finder AppleShowAllFiles YES
The command to hide Mac hidden files: defaults write com.apple.finder AppleShowAllFiles NO After
typing, click Enter to exit the terminal and
restart Finder can restart Finder: [mouse click the apple logo in the upper left corner of the window -> force exit -> Finder -> restart]

Simply put, each directory of the Mac will have a file called .DS_Store, which is used to store some Meta information of the current folder. So every time you check the status of the Git directory, if you don’t add the .DS_Store file, there will be a prompt of Untracked files:. After adding it, there will be a prompt of Changes not staged for commit:. Is it particularly annoying like a fly ? To solve this annoying little fairy, we need to use the .gitignore file to configure the files that need to be ignored in the Git directory.
The .gitignore file is used to ignore files, and its specifications are as follows:
1. All blank lines or lines beginning with the comment symbol # will be ignored by Git.
2. You can use standard glob pattern matching.
3. The matching pattern followed by a backslash (/) indicates that the directory is to be ignored.
4. To ignore files or directories outside the specified mode, you can add an exclamation mark (!) before the mode to reverse it.
Key points of glob mode:

  1. *: any number of any characters
  2. ?: Match an arbitrary character.
    So, we only need to create a .gitignore file in the corresponding Git directory, and then configure the .DS_Store. The steps are as follows:
    1. Use touch .gitignore to create a .gitignore file (already Some go directly to the second step)
    wdw:test wdw$ touch .gitignore
    2.open .gitignore, enter .DS_Store and then enter */.DS_Store

Add and save directly without .gitignore, and add it at the end of the file if you already have .gitignore

3. Save it to take effect. Here, the .DS_Store of the current directory and the .DS_Store of its subdirectories are ignored,
so that the problem is solved? No, because in the future use, I found that I need to add such a .gitignore configuration to all Git directories, and my heart is broken. Is there a way to configure it globally? Make this configuration effective for all Git directories. git config can help us.
The git config --list command allows you to view the existing configuration, (here we will ignore other configuration items, interested students can click here to learn more) In fact, it is a file, the file The location is in the user's root directory and the name is .gitconfig. Here are the steps to add a global ignore file:

  1. Create a ~/.gitignore_global file and write the files that need to be ignored globally. The syntax is the same as that of .gitignore
  2. Introduce .gitignore_global file in ~/.gitconfig
    excludesfile = /Users/reon/.gitignore_global
    can also be achieved by git config --global core.excludesfile/Users/reon/.gitignore_global command
  3. The configuration is successful, you can go to verify whether it takes effect.
    At this point, the operation of ignoring the file is done.

How to delete files on github

If you want to delete the original file on github?

Sometimes, for some reasons, you need to delete the files uploaded to git, but if you simply delete the local files and then perform the commit operation, only the local files are deleted, and the remote files still exist. You can use the following command to delete the file in the stage first, then submit, and then push to the remote, then the file on github does not exist.
For example, delete the execution operation of the .DS_Dtore file on github, enter the corresponding directory, and perform the following operations in the terminal

  1. git rm --cached filename
  2. git commit -m “hehe”
  3. After git push origin is
    executed, refresh github again, you will find that the file you want to delete at this time has disappeared.

Guess you like

Origin blog.csdn.net/universsky2015/article/details/108544470