-2

i'm trying to insert commit message for modified files as well no-modified files but commit failes.

 git commit -m "${commit_mmes}" "${fil}" $(git ls-files | grep "\.txt" | tr '\n' ' ' | awk '{$1=$1};1')

 git commit -m 'Master Merge-Commit message' music/file1.mp3 'music/file2.txt music/file4.txt3music/file5.txt music/file4.txt'

the response of git ls-files command still comes as below

 'music/file2.txt music/file4.txt3music/file5.txt music/file4.txt'

how to remove it?

Vinoth
  • 189
  • 1
  • 1
  • 9
  • Could you please post sample output of `git ls-files` inn your question and let us know then, I am pretty sure we could do it in a single command. Let us know once you are done with editing your question. – RavinderSingh13 Mar 17 '20 at 12:38
  • echo $(git ls-files | grep "\.txt" | tr '\n' ' ' | awk '{$1=$1};1')music/file2.txt music/file4.txt3music/file5.txt music/file4.txt – Vinoth Mar 17 '20 at 12:40
  • while running it from the console, the response comes without single quotes but i im running it same command in bash script git consider it as string as single txt file and fails – Vinoth Mar 17 '20 at 12:42
  • error: pathspec 'music/file2.txt music/file4.txt3music/file5.txt music/file4.txt' did not match any file(s) known to git. --- this is the response – Vinoth Mar 17 '20 at 12:43
  • I don't have git with it so can't test commands, I thought may be I could help with existing commands of yours; someone who has git console could help you better here. – RavinderSingh13 Mar 17 '20 at 12:44
  • Sorry for late reply, i have found the problem its due to previous field separator caused problem so i just did unset IFS. – Vinoth Sep 03 '20 at 02:58

2 Answers2

0

git ls-files encodes "unusual" characters unless -z is given:

Without the -z option, pathnames with "unusual" characters are quoted as explained for the configuration variable core.quotePath (see git-config[1]). Using -z the filename is output verbatim and the line is terminated by a NUL byte.

Also, git ls-files is able to filter directly without grep.

So you can do:

git ls-files -x '*.txt' -i -z |\
xargs -0 git commit -m "${commit_mmes}"
jhnc
  • 11,310
  • 1
  • 9
  • 26
0

I have found the problem, previously assigned IFS value not unset or removed. hence it was kept used in shell script. once IFS removed, I was able to commit files.

Vinoth
  • 189
  • 1
  • 1
  • 9
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '21 at 12:05
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '21 at 13:04