Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:44:33+00:00 2026-06-07T03:44:33+00:00

I am observing a strange behavior while using git-status with pathspecs. I would like

  • 0

I am observing a strange behavior while using git-status with pathspecs. I would like your opinion on whether it is the expected behavior, or an undefined behavior in git.

Initial setup

$ mkdir main && cd main
$ git init .
Initialized empty Git repository in d:/temp/main/.git/
$ touch test[1].txt
$ touch test[2].txt

The following ones are understandable

$ # 1. escaped square brackets
$ git status test\[1\].txt --short        
?? test[1].txt

$ # 2. escaped square brackets with range
$ git status test\[[1-9]\].txt --short    
?? test[1].txt
?? test[2].txt

$ # 3. unmatched range, with what looks like a fallback to literal comparison
$ git status test[1].txt --short          
?? test[1].txt

Additional setup for unexpected behavior

$ touch test1.txt

Unexpected behavior

$ # 4. matched range, so no fallback to literal comparison (this one looks OK)
$ git status test[1].txt --short
?? test1.txt

$ # 5. escaped square brackets => I would expect only test[1].txt to be returned
$ git status test\[1\].txt --short
?? test1.txt
?? test[1].txt

$ # 6. escaped square brackets with range => I would expect only test[1].txt 
$ # and test[2].txt to be returned
$ git status test\[[1-9]\].txt --short
?? test1.txt
?? test[1].txt
?? test[2].txt

$ # 7. only escaping the last square bracket
$ # result looks similar to the 5th case
$ git status test[1\].txt --short
?? test1.txt
?? test[1].txt

Additional setup for more fun

$ git add test1.txt
$ rm test1.txt
$ touch test2.txt

More unexpected behavior

$ # 8. ???
$ git status test[1].txt --short
AD test1.txt
?? test[1].txt

$ # 9. We lost test1.txt ???
$ git status test[1-2].txt --short
?? test2.txt

$ # Woo... Should this really work?
$ git status test[*.txt --short
AD test1.txt
?? test2.txt
?? test[1].txt
?? test[2].txt

I’m a bit confused there. I’ve read the Git documentation related to pathspec and it’s not that detailed.

Could anyone help me understand the logic behind?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:44:35+00:00Added an answer on June 7, 2026 at 3:44 am

    There are a lot of things to discuss here but I will try to focus on: 1. the logic behind this, 2. How it modifies the behavior.

    The logic

    Most of the path expansion is done by the shell (hence my comment). Some is done by git, when it has what it takes.

    Some tests

    The setup

    I used this program to investigate the issue:

    include <stdio.h>
    
    int
    main(int argc, char **argv)
    {
        int i;
    
        for (i = 1; i < argc; i++) {
                puts(argv[i]);
        }
    }
    

    I know, it’s very high-skill programming.

    Tests

    We can now have a look at what is going on, and see how the shell modifies what git receives:

    Point 1, 2, 3, 4: Everything is working fine, running the small program will give you the same.

    $ ./a.out test\[1\].txt test\[[1-9]\].txt test[1].txt
    test[1].txt
    test[1].txt
    test[2].txt
    test[1].txt
    

    Point 5, 6, 7: This time it’s handled by Git, behavior is not that surprising (doing both glob and literal comparison)

    $ ./a.out test\[1\].txt test\[[1-9]\].txt test[1\].txt
    test[1].txt
    test[1].txt
    test[2].txt
    test[1].txt
    

    Point 8, 9, 10: Well, according to what we’ve seen before, it’s no longer surprising. For 9., no bash comparison matches with test1.txt (removed, hence, … removed)

    $ ./a.out test[1].txt                         
    test[1].txt
    
    $ ./a.out test[1-2].txt          
    test2.txt
    
    $ ./a.out test[*.txt
    test[1].txt
    test[2].txt
    

    Conclusion

    If you want to test the way Git handles pathspec, you should enclose your path in double quotes:

    $ ./a.out "test[*.txt" "test[1\].txt"
    test[*.txt
    test[1\].txt
    

    Hope it helped,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm observing some strange behavior when using the F# interactive interpreter. Running the following
I'm observing a strange behavior scheduling a job in Quartz using a CronTrigger that
Using OneNote 2010 doing some C# interop stuff. Observing some very strange behavior, which
I'm observing some strange behavior with a local variable within a nested for loop
’m observing a strange behavior from my application which I hope you can explain
I'm observing some strange behavior in my code and I'm trying to track down
Okay, so I'm observing some behavior that I would certainly call 'unexpected' and I'm
I'm working with shaders just now and I'm observing some very strange behavior. I've
Observing rather strange behavior in relative layout. This is the initial state: Defined as:
I'm using jdk1.6_20 on Linux 2.6 . I am observing a behavior where the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.