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
  • you should add your files in staging area those file which is modified and then do commit Commented Jun 26, 2020 at 4:49

1 Answer 1

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}"
Sign up to request clarification or add additional context in comments.

2 Comments

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)"".
@AngelOmarRojasPacheco OK. I have edited the answer accordingly.

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.