Shanyue. tech/bug/mac-git… Welcome to my blog for more articles
When writing components with React, it is recommended that Component names begin with a capital letter.
Some students named the React component files in lower case, but later changed them to uppercase to keep the team aligned. Git didn’t notice the change in case, and this caused problems.
Let’s go over the logic one more time:
- Xiao Ming writes components
button.js
, submit the code - Xiaoming felt that the component was named improperly and changed to
Button.js
- Xiaoming and modify all files on its reference, the local environment is running properly, submit code
- The build server uses Git to pull code to build, and Git is aware of that
button.js
Case changes for all referencesButton.js
The component failed
To recreate the process of making a mistake:
# At first the test file is made up of content~ / Documents/ignorecase - test (master ✔) cattest
hello
# change file test to uppercase file test~ / Documents/ignorecase - test (master ✔) mvtest Test
Git status has not changed
~/Documents/ignorecase-test(master ✔)
~/Documents/ignorecase-test(master ✔) git ls-files
test~ / Documents/ignorecase - test (master ✔) ls testCopy the code
The solution
Use Git mv to change the file case again in git staging
$ git mv test Test
Copy the code
However, there are some problems when modifying folders:
fatal: renaming ‘dir’ failed: Invalid argument
Use the following stupid method to modify:
$ git mv dir DirTemp
$ git mv DirTemp Dir
Copy the code
Prevention programs
Are there any precautions?
Git does not ignore case by default. No, that would create more problems.
Change to not ignore case
[core]
ignorecase = false
Copy the code
Here are the questions that arise:
- When you change the file name, you add two files to your Git workspace and cannot delete them
- Git RM deletes both files from the workspace
~ / Documents/ignorecase - test (master ✔) lstest~ / Documents/ignorecase - test (master ✔) mvtestTest ~/Documents/ignorecase-test(Master University) ls Test ~/Documents/ Ignorecase-test (Master University) Git status On Branch master Untracked files: (use"git add <file>..." to include in what will be committed)
Test
nothing added to commit but untracked files present (use "git add"To track) ~/Documents/ignorecase-test(Master University) Git add-a ~/Documents/ Ignorecase-test (Master University) Git ls-files testtest~ / Documents/ignorecase - test (master ✗) git rmtest
rm 'test'~/Documents/ Ignorecase-test (Master University) Git add-a ~/Documents/ Ignorecase-test (Master University) git ls-files ~ / Documents/ignorecase - test (master ✗)Copy the code
conclusion
Use git mv -f and mv to change the file name at the same time to avoid inconsistency between the local file system and the repository code.