preface

Because that year too young, seniority is not deep enough!! Now I want to correct the folder name (common => common), and I find a very strange phenomenon! Git is case-insensitive to file (folder) names !!!! It raises some questions. Finally through access to information to be resolved, then! Write this post for the record. Go ~ eat peanuts with dregs 🥜 drink beer 🍺 dry up ~

Demo partial directory structure

  • Master branch code and file directory

    # master branch original directory. ├ ─ ─ main. Js └ ─ ─ the SRC └ ─ ─ components └ ─ ─ common ├ ─ ─ FootCell │ └ ─ ─ index. The vue ├ ─ ─ Pagination │ └ ─ ─ index. The vue ├ ─ ─ Table │ └── impCopy the code
    // main.js
    const files = require.context('.. /components/common'.true./\.vue$/)
    Copy the code

The preparatory work

Analog multiuser

  • User1 branch: feature/user1

  • User2 branch: feature/user2

    At this point, two users, User1 and User2, have pulled the project from their respective computers.

SAO operation to start the first

Filename changes are not synchronized to the remote end, but the reference path is!

  • Git is case-sensitive. User1 is case-sensitive. Will! To know! Way!!!

[user1] Synchronizes changes remotely

Change file name + Change reference path

Git will not detect the file name change (case) because git is not case-sensitive, so you must change a file to let Git detect the change. To commit! The file name change caused the reference path to change too! Therefore, it can be submitted this time

  • Because the green is too ruthless, the mood is not very good began to SAO operation pit teammates! Common => common The following information is displayed:

      # common => COMMON. ├ ─ ─ main. Js └ ─ ─ the SRC └ ─ ─ components └ ─ ─ COMMON ├ ─ ─ FootCell │ └ ─ ─ index. The vue ├ ─ ─ Pagination │ └ ─ ─ index. The vue ├ ─ ─ Table │ └── impCopy the code
    // main.js
    const files = require.context('.. /components/common'.true./\.vue$/)
    Copy the code

    Finally, the code is committed to the remote end and user2 is told that the code has been updated

[user2] response

pullcode

  • User2 then pulls and merges user1’s code into its branch. The result is as follows:

      # no change in common => common!. ├ ─ ─ main. Js └ ─ ─ the SRC └ ─ ─ components └ ─ ─ common ├ ─ ─ FootCell │ └ ─ ─ index. The vue ├ ─ ─ Pagination │ └ ─ ─ index. The vue ├ ─ ─ Table │ └── impCopy the code
    // main.js has changed!!
    const files = require.context('.. /components/COMMON'.true./\.vue$/)
    Copy the code

    At this time, “retribution” too suddenly, the project reported wrong! The referenced path is COMMON and the actual project path is COMMON

  • User2 then wonders why the file name has not changed. Thus opened the way of exploration ~~

To explore the problem

User1 was in a bad mood because of a wave of green, causing user2 to cause a bug, but it just aroused user2’s curiosity.

  • Why user1 is COMMON when I get COMMON?

    Finally user2 finds the answer! Git is not case sensitive to filenames. Ok, so what’s the next step to solve the problem?

Warm prompt

Because Git is case-insensitive by default, you won’t notice if you just change the file name. Unable to commit, so this test changed the file name along with other changes in order to commit!

To solve the problem

Since user2 already knows that Git default is case-insensitive, let user2 be case-sensitive. How simple!

[user2] Updates the change

1. Enable the sensitive mode

git config core.ignorecase false # Make you sensitive
Copy the code

User1 does not synchronize file name changes to the remote end at all! Git is case-insensitive! But the file reference path has changed, which causes someone else (user2) to report an error due to the file path change.

2. Switch branches and pull the latest code

  • Cut the branch checkout

    git che master
    Copy the code
  • Pull pull code

    git pull
    Copy the code

    At this point, you will find that the project cannot start because the file path reference in main.js has been changed by common => common, but the actual file name is still common

3. Manually change the file name

  • common => COMMON

4. Temporary, commit, push, branch, merge into feature/user2 branch

  • Staging the add

    git add .
    Copy the code
  • Submit the commit

    Git commit -m user2 Manually synchronize the file nameCopy the code

  • Push push

    This step is to synchronize the file name change to the remote end for user1, for user3... Such as the use of
    # if other users are the same users as before, the problem described in this article will also occur.
    # method ~~ is the current article ~~ hahaha
    git push
    Copy the code
  • Cut the branch checkout

    git che feature/user2
    Copy the code

  • Merge master to feature/user2 branch

    git merge master
    Copy the code

To viewcommitrecord

SAO operation to start the second

The file name change is actually synchronized to the remote end, and the reference path is synchronized to the remote end!

  • This time user1 knows that git is case-insensitive, user2 also knows that git is case-insensitive.

[user1] Synchronizes changes remotely

  • user1Branch:feature/user1

1. Make her sensitive and sensitive

git config core.ignorecase false # emmmmm... An sensitive
Copy the code

2. Change the file name & file reference path

  • common => COMMON

  • Changing the reference path

    / / the old
    const files = require.context('.. /components/common'.true./\.vue$/)
    
    / / new
    const files = require.context('.. /components/COMMON'.true./\.vue$/)
    Copy the code

3. Temporary (Add) & Commit (Commit)

  • Staging the add

    git add .
    Copy the code
  • Submit the commit

    git commit -m <msg>
    Copy the code

4. Switch branches

  • git checkout master

4. Merge to the master and pull to the remote end

  • Merge results are as follows:

    git merge feature/user1 The branch of user1 is merged into the local master
    Copy the code

  • Push push

    git push # push to remote master
    Copy the code

[user2] Updates the change

  • user2Branch:feature/user2

1. Enable sensitive mode · Case 1

git config core.ignorecase false
Copy the code

2. Cut branches & pull code

  • Cut the branch checkout

    git checkout master
    Copy the code
  • Pull pull code

    git pull Update the master branch
    Copy the code
  • The results are as follows:

    # the results of the errorKaKa:test2 XXX $git pull update 5f318b9.. 5174f2e error: The following untraced files in the workspace will be overwritten because of the merge operation:  src/components/COMMON/FootCell/index.vue src/components/COMMON/Pagination/index.vue SRC/components/COMMON/Table/index. The vue SRC/components/COMMON/TitleCell/index. The vue please move or delete before the merger. Is terminatedCopy the code

    Attention! Once the above problem is triggered, all subsequent operations such as check,switch,pull, etc will report this error!!

    Delete or move the original common folder, and then pull(check,switch)

    • The results are shown below:

      The common file name has been changed to common

3. Switch branches & merge code

If the problem in the previous step is resolved then there is nothing abnormal in this step, user2’s branch code has been updated, right

  • Cut the branch checkout

    git checkout feature/user2
    Copy the code
  • The merge code

    git merge master # Update feature/user2 branch
    Copy the code

4 look atcommitrecord

  • The diagram below:

5 Congratulations

1. Disable sensitive mode. Case 2

git config core.ignorecase true Git is insensitive by default
Copy the code

2. Cut branches & pull code

  • Cut the branch checkout

    git checkout master
    Copy the code
  • Pull pull code

    git pull Update the master branch
    Copy the code

    The results are shown below:

    Is that a surprise?

    Although the remote file name has been changed from common => common, the local file name is still the old common when user2 pulls

3. Change the file name, switch branches, and merge master

  • Change the file name common first => common

  • Then switch branches:

    git checkout feature/user2
    Copy the code

    The COMMON folder is empty

  • The result of the merge is as follows:

    git merge master
    Copy the code

    The COMMON folder has content again

4. Check thecommit

  • The records are as follows:

5. Congratulations

Another way is git rm

  • Delete a folder rm

    Git rm < folder path > -r# -r means recursion
    Copy the code
  • Deleting a file rm

    Git rm < path >Copy the code

[user1] Synchronizes changes remotely

1. Enable sensitive mode · Case 1

git config core.ignorecase false
Copy the code

2. Make copies

common => common copy

You cannot directly change common Copy to common after copying a copy (common still exists)

3. Run rm to delete the common folder

 git rm ./src/components/common -r # -r means recursion
Copy the code

4. Restore the name

  • common copy => COMMON

    Change the name of the copy (common Copy => common) and proceed to step 3 ???? That’s a good question. Clapping 👏

    To see the result

    I would have liked to have done this, but now that I think about it, in case insensitive:

    common === COMMON // true,
    Copy the code

    So there is no problem with the above tips I personally think

5. Temporary, commit, merge to master, and push to remote

In this step you will get the following error message causing the branch switch to fail (not quite the same as above)

  • Check out the problem

    KaKa:testxxxx$ git che master error: The following untraced files in the workspace will be overwritten due to a check out operation:  src/components/common/FootCell/index.vue src/components/common/Pagination/index.vue SRC/components/common/Table/index. The vue SRC/components/common/TitleCell/index. The vue please move or delete before switching branches. Is terminatedCopy the code

    The project structure at this point looks like this:

    . ├ ─ ─ the README. Md ├ ─ ─ the main, js └ ─ ─ the SRC └ ─ ─ components └ ─ ─ COMMON < =# key! Here!!!!!! And there is no common├── ├─ Pagination │ ├─ Pagination │ ├─ indexCopy the code

    There is no common folder! ! Then there is no solution?? But no! So let’s say:

    • The COMMON = > COMMON

    • To delete a common

    • Finally, run git check master

    Ignore the deleted file changes and go directly to Git Checkout Master

  • The merge out of the question

    KaKa-3:testXXXX $git merge feature/user1 update 5f318b9.. 24b399d error: The following untraced files in the workspace will be overwritten because of the merge operation:  src/components/COMMON/FootCell/index.vue src/components/COMMON/Pagination/index.vue SRC/components/COMMON/Table/index. The vue SRC/components/COMMON/TitleCell/index. The vue please move or delete before the merger. Is terminatedCopy the code

    There is no COMMON, same as above:

    • thecommon= >COMMON
    • And then deleteCOMMON

    • The lastgit merge feature/user1It’s ok

6. Check thecommitrecord

  • The diagram below:

1. Disable the sensitive mode. Case 2

git config core.ignorecase true
Copy the code

2. Change the file name

  • common => COMMON

    Then an embarrassing scene it happened!! The diagram below:

    Oh, my gosh! Git has not detected any file changes!

3. The pawn!

  • In this case, either give up or turn on sensitive mode! If it’s on that’s case one

[user2] Updates the change

  • The initial directory of user2’s master branch is as follows:

    .├ ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ├─ Table │ ├─ lessons.├ ─ lessons.├ ─ lessons.├Copy the code

1. Enable sensitive mode · Case 1

git config core.ignorecase false
Copy the code

Pull the latest code

KaKa:test2 XXXX $git pull update 5f318b9.. 24b399d error: The following untraced files in the workspace will be overwritten because of the merge operation:  src/components/COMMON/FootCell/index.vue src/components/COMMON/Pagination/index.vue SRC/components/COMMON/Table/index. The vue SRC/components/COMMON/TitleCell/index. The vue please move or delete before the merger. Is terminatedCopy the code

As expected will be consistent with the beginning of the situation, here will not repeat repeat, refer to the above can be solved.

3. Check thecommitrecord

  • The diagram below:

1. Disable the sensitive mode. Case 2

git config core.ignorecase true
Copy the code

2. pullThe latest code

  • The following figure

    As mentioned above, all changes have been made, but the filename is not automatically changed because it is case-insensitive locally

3. Manually change the file name

common => COMMON

4. Switch branches, mer master code

  • Cut the branch checkout

    git checkout feature/user2
    Copy the code
  • The merge code

    git merge master
    Copy the code

5. Check thecommitrecord

  • The diagram below:

conclusion

To sum up, the conclusion is that there is already a situation when many people cooperate in development

  • The first way is user1 two ways, user2 two ways, four ways. And all files are marked AS A

    • You can imagine that the remote file name will always be common instead of Common. Everyone will always have this problem (you have to manually change the file name locally).

    • User2 can update the master branch code synchronously with error, delete or move file location according to the prompt. (Delete the most simple and intuitive)

    • The sensitive mode of the modifier (user1) is enabled, but the notified (user2) is not enabled. Although the file name has been changed and synchronized to the remote end, when user2 (master) pulls the file name, it will find that the local file name is still common. You just need to manually change the file name and merge into the user2 branch

    • The sensitive mode is not enabled by the modifier (user1), and the notified (user2) is enabled by user1. User1 thinks that the file name has been successfully changed and synchronized to the remote end, but it is not synchronized to the remote end. User2 manually changes the file name, and pushes the file to the remote end after the change, so that the problem of incorrect file reference path of everyone can be solved

  • The second way

    Git rm. Changing files in this way is marked as R

conclusion

All content has been tested for several times, a practice a record of the form to write, and finally checked several times, there is no visual problem, if there is a problem please leave a message to inform it ~