4

I can not commit and pull because of an unmerged file.

U    user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

I have tried git add -A and then commit, but it's still not working. When I tried

git add user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG

it says

-bash: syntax error near unexpected token `('

Besides, I have manually removed the file and even the directory post_img and then committed again, but it remains the same. What would be the problem?

3 Answers 3

9

Try this:

git add "user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG"

Otherwise, Bash will try to do something with that (2) in the file name.

If you removed the file and want to also remove it from Git, you have to call rm instead:

git rm "user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG"

Or you can also use git add -u to update files Git already knows about (which will remove the file too).

Sign up to request clarification or add additional context in comments.

4 Comments

still not working because i have deleted the file and it says can not match any
If you have removed the file, you have to use git rm "…" instead.
Yes, I have already used git rm "...", and it says user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG: needs merge fatal: pathspec 'user_data/user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG' did not match any files
It works, and I have to do something like rm user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003\(2\).JPG
2

You could also do this:

git add user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003\(2\).JPG.  

It's the parentheses in the file name that are causing problems.

Comments

1

ShellCheck lets you know what the syntax problem was all about:

   1  git add user_data/post_img/kesongxie/LuYWf7nM915SQ0X/003(2).JPG
                                                              ^––SC1070 Parsing stopped here because of parsing errors.
                                                              ^––SC1036 '(' is invalid here. Did you forget to escape it?

The way to resolve that is to escape the ( and the ). Just put a \ before these and you will be fine - \( and \)

3 Comments

This is what happens if I escape parentheses: # git add ./**/*.\(po|mo\) bash: mo): command not found
That is an awesome tip. ShellCheck can apparently also be installed locally. E.g., supposedly by sudo apt install shellcheck on Ubuntu.
Using ShellCheck, I was able to fix a Git hooks script in short order (rather than trying to search on Stack Overflow for the error messages - very, very inefficient. Sadly).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.