Jaskaranbir Singh
Jaskaranbir Singh

Reputation: 2034

How to determine if files I modified have new commits on github?

First, sorry for such a confusing pesky title, I really can't find a better way to describe this (would appreciate any changes suggested to post).

The problem

I synced a github repo. And also modified some files and codes inside according to my needs. But if I want to resync and update my tree to latest commits.

will my changes be overwritten?
Or will repo simply ignore modified files and move on to other files?
Or will there be patching process (I dont think this would be case since chances of problems with auto-patching are quite high)?

My guess is that it skips over modified files. And I may need to manually get the new commits from repo. But how to determine which files that have been modified have new commits? I just want to determine it, then probably manually fetch and modify them manually.

To clarify:

Consider files named "abc" and "def" which I modified. The repo owner updated his repo with a lot of new commits. I ran repo sync and it synced all files to newer commits except those I modified. Now how do I determine if the files that repo owner updated include "abc" and/or "def" too (assuming I myself modified a lot of files, so I can't manually check if each file has new commit or not)?

I don't want to see what files I have modified or a complete list of files with new commits, I just want to see if the files that I modified have new commits or not.

Is there any such possible way?

I do know how to determine files that are changed using `git status,

but how do I want to check if those changed files have any new commits.

Upvotes: 0

Views: 112

Answers (2)

Magnus Bäck
Magnus Bäck

Reputation: 11571

When running repo sync, Repo will rebase any non-published topic branches (i.e. branches you haven't uploaded to Gerrit with repo upload).

Or will there be patching process (I dont think this would be case since chances of problems with auto-patching are quite high)?

Git will try, but if there's a conflict that it can't resolve by itself you have to step in and help out.

Consider files named "abc" and "def" which I modified. The repo owner updated his repo with a lot of new commits. I ran repo sync and it synced all files to newer commits except those I modified.

No. Either Repo rebases your branch (and updates/merges all files) or it doesn't do anything and it's up to you need to rebase or merge from the upstream. Git never does partial updates.

I dont want to see what files I have modified or a complete list of files with new commits, I just want to see if the files that I modified have new commits or not.

I think you're asking the wrong question, but sure, you can list the commits that modify a particular set of files or compare two commits and only display the differences in a particular set of files. Both git diff and git log accept one or more paths to files that you want to restrict the output to. To find the files you can use git ls-files -mo to obtain dirty files and untracked files in your workspace, git diff-tree --name-only -r HEAD~..HEAD to get the files modified by the most recent commit, and so on.

Putting it all together, the following command fetches the most recent state from the upstream and shows the new commits (git log HEAD..origin/master) that touch upon files that you yourself have modified on the current branch since the last update from the upstream (git diff-tree --name-only -r origin/master..HEAD):

git fetch
git log HEAD..origin/master -- $(git diff-tree --name-only -r origin/master..HEAD)

A Unix-like shell is assumed. On Windows things may look differently.

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142094

You can use git hook to track the list of files.
In your post-receive hook search for the given file and do what ever you need to do.

Another option is to track it manually using the follow flag
git log --follow <path>, it will print out the list of changes made to the given file in each commit

Upvotes: 0

Related Questions