Search code examples
gitpushdiffpull

How to differentiate between files that need to be pulled in Git, and files that are committed locally and ready to be pushed


How do I determine which files in my local repository are committed and ready to be pushed, and which files have been pushed by someone else in the meantime and need to be pulled, once you've already done a 'git fetch'?

For example:

git fetch
...

$ git diff --stat --staged origin/Release_Candidate

 AP4Configuration/ChangeLog.txt    | 3 +--
 AP4Configuration/appsettings.json | 3 +--
 Local5.txt                        | 1 -
 3 files changed, 2 insertions(+), 5 deletions(-)

I staged and committed appsettings.json and local5.txt and they are ready to be pushed as part of the local commit(s), but Changelog.txt needs to be pulled from the repository on the server.

How can I tell that Changelog.txt is in a commit on the server that needs to be pulled, and appsettings.json and local5.txt are from a commit on my local machine that needs to be pushed?

I get the same result from:

git diff --stat --cached origin/Release_Candiate
git diff --stat --HEAD origin/Release_Candiate

Is there any way I can determine which files need to be pulled, and which ones are ready to push?

For example, I would like to see the files in the local commit(s) that will be pushed, without seeing the ones that are in the latest commit on the server ready to be pulled.

I am updating a GUI Git interface for my workplace, and the users need to see this information. Thanks.


Solution

  • I've finally figured out what I need to do.

    After a 'git fetch', the following command shows both local and remote changes:

    $ git diff --stat --cached origin/Release_Candidate
    
     AP4Configuration/ChangeLog.txt    | 3 ++-
     AP4Configuration/appsettings.json | 3 ++-
     Local5.txt                        | 1 +
     3 files changed, 5 insertions(+), 2 deletions(-)
    

    But to see the file(s) that I myself modified, and that will be pushed as part of my local commits:

    $ git diff --stat --merge-base origin/Release_Candidate
    
     AP4Configuration/appsettings.json | 3 ++-
     Local5.txt                        | 1 +
     2 files changed, 3 insertions(+), 1 deletion(-)
    

    This list does not show Changelog.txt. It now only shows the files I committed locally. Therefore I can see which files in the commits will be pushed, and which ones will need pulling from the server-side commits.