1

how to get a file name using git, well I want add file name automatically, for example bellow:

git ls-files -m # show me just files affected with changes
example/example.py

and I want to loop all my project, and get a name files and put that name in a string like bellow:

example.sh
# first check status
git status
# show files affected
git ls-files -m
echo "your changes in files $(git ls-files -m)" 
# add files
git add .
# add var name files
NAME_FILES = git ls-files -m # NOT WORKING
# add commit
git commit -m "files added $(NAME_FILES)" # but this line not working

when I show logs just display "files added " and not display names files added.

please help me

thanks

1 Answers1

1

If you want to add modified files

git add -u

But if you do a git ls-files after the git add step, then you needs (using this):

NAME_FILES=$(git status --porcelain|tr '\n' ' ')
git commit -m "files added ${NAME_FILES}"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • sorry for the confusion, but I need is save a name file in a var and put that name into the git commit, like this: "NAME_FILES = git ls-files -m and when commited like this git commit -m "your files affected in $(NAME_FILES)"". – Angel Omar Rojas Pacheco Jun 26 '20 at 21:51
  • @AngelOmarRojasPacheco OK. I have edited the answer accordingly. – VonC Jun 26 '20 at 22:16