How can I know all git changes using some GitHub command.?

43 views Asked by At

I am using

git status --porcelain -uall

It gives a result like this:

?? FOLDER1/FOLDERCHILD/ETC/FILE1.cs

From this, I want to remove ?? and keep the rest, but if I make some commits, then my Git changes will be 0 and this query won't work.

How can I retrieve all the file names/paths that have been committed in my branch?

I tried

git diff --name-only main...

This looks like a good option but it returns only the file names that are committed (reverse of above problem).

I don't want to use the GitHub API, only Git commands.

I want to know if there any command that can give me all of my Git changes:

  • file path/name that I have commited in my branch
  • file path/name that I have not committed and are present in unstaging as well as in staging area

I would like a similar result to what we get when we open a pull request.

1

There are 1 answers

0
Jib On

An easy way is to simply get rid of the leading part using sed.

For instance, the bellow command gives you the list of files (without any further details):

$ git status --porcelain=v1 | sed -E 's/^.{2} //'
sources/data/f1.c
sources/data/f2.c
sources/data/f3.c

More details: Here, the sed command is used for replacing a specific pattern (in this case the regular expression ^.{2} which matches "the first two characters at the beginning of the line with a white space") with nothing.

An improved solution could be to merge the result of the git status and git diff commands in order to obtain the full list of edited files (no matter their status as long as they are tracked).

The command would look like this:

$ (git status --porcelain=v1 | sed -E 's/^.{2} //' && git diff --name-only main...) | sort | uniq
include/data.h
sources/data/f1.c
sources/data/f2.c