Guide | In general development, the program is developed on the Mac and Git is used for version management. When writing Component using React, it is generally recommended that the first letter of the component name be capitalized. |
In general development, the program is developed on the Mac and Git is used for version management. When writing Component using React, it is generally recommended that the first letter of the component name be capitalized.
"When some students named the files of React components, they were lowercase at first, and later changed to uppercase in order to keep the team consistent. However, git won't find the change in case, and there is a problem at this time."
Sort out this logic again:
- Xiao Ming wrote the component button.js and submitted the code.
Xiao Ming felt that the component was not named properly. He changed it to Button.js
and modified all files to refer to it. The local environment is running normally. The submit code
build server pulls the code through Git and builds it. Git In order to recognize that the case of button.js has changed, all components that reference Button.js report an error and fail
Let's reproduce the process of making mistakes:
# 刚开始 test 文件是由内容的
~/Documents/ignorecase-test(master ✔) cat test
hello
# 把 test 文件改成首字母大写的 Test 文件
~/Documents/ignorecase-test(master ✔) mv test Test
# 注意此时 git status 并没有发生改变
~/Documents/ignorecase-test(master ✔)
~/Documents/ignorecase-test(master ✔) git ls-files
test
~/Documents/ignorecase-test(master ✔) ls
Test
solution
Solve the problem by changing the case of the file again in the Git staging area through git mv
$ git mv test Test
But there will be some problems when modifying the folder:
fatal: renaming 'dir' failed: Invalid argument
Use the following stupid method to modify:
$ git mv dir DirTemp
$ git mv DirTemp Dir
Prevention plan
Are there any precautions?
"Git ignores case by default. If you change it to not ignore case, is it OK? No, it will cause more troublesome problems."
Change to not ignore case
[core]
ignorecase = false
The following are the problems that arise:
- "When modifying the file name, two files were added to the Git workspace at once, and they could not be deleted."
"When git rm deletes the file, both files in the workspace are deleted"
~/Documents/ignorecase-test(master ✔) ls
test
~/Documents/ignorecase-test(master ✔) mv test Test
~/Documents/ignorecase-test(master ✗) ls
Test
~/Documents/ignorecase-test(master ✗) git status
On branch master
Untracked files:
(use "git add ..." 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 ✗) git add -A
~/Documents/ignorecase-test(master ✗) git ls-files
Test
test
~/Documents/ignorecase-test(master ✗) git rm test
rm 'test'
~/Documents/ignorecase-test(master ✗) git add -A
~/Documents/ignorecase-test(master ✗) git ls-files
~/Documents/ignorecase-test(master ✗)
to sum up
Use git mv -f and mv to change the file name at the same time to avoid inconsistencies between the local file system and the code in the warehouse. Linux should be learned like this