简体   繁体   中英

Before pushing to a remote git repo, is there a way of getting a list of all the files that would get pushed (without parsing the call to git status)?

I am trying to avoid the need to parse the output of "git status". Is there a command that will return a list of all the committed files that will get pushed on the next "git push" command?

You should try git diff --stat --cached origin/<<branch name>>

Example: git diff --stat --cached origin/master

The --stat generates a diffstat. The --cached is to view the changes you staged.

Let me know if this works.

Short answer

git log --pretty=format:"" --name-only @{upstream}.. | sort -u

Explanation

--pretty=format:"" to suppress commit info

--name-only asks for the list of files

@{upstream} is a construct to describe the remote branch the current one is linked to. It's not a placeholder, it's meant to be written as is.

@{upstream}.. (mind the .. which makes it a range ) means everything on current branch but is unknown to the remote branch.

Of course, it's more useful to have it sorted in case you have many commits modifying the same files. Use | sort -u | sort -u for this purpose.


Final note : Make it an alias!

# pf = Push Files (could be whatever else you prefer)
git config --global alias.pf '!git log --pretty=format:"" --name-only @{upstream}.. | sort -u'

# then just
git pf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM