0

My current workflow for a fairly large project (a fork of another project) requires me to regularly cherry-pick only certain commits, with files handily found across one subdirectory.

Ideally. I could simplify the workflow by pulling the latest commits referencing a specific file (and all its dependencies, obviously. I want the full, unaltered commits).

i e "pull fileA" should pull in all the new commits referencing changes to fileA.

Is there a way to somehow do this?

Expected result: Pull/merge all new commits referencing a specified file from a remote repository.

Current workflow: Browse through a file's history, note (set of) commit SHA1, git cherry-pick <SHA1>

user237251
  • 211
  • 1
  • 10
  • What do you mean with `pull`? Is it the pull that `git pull` does? Please clarify what you want to achieve. – C-Otto Jan 17 '18 at 09:03
  • Sorry. By pull I mean git pulling them from a remote repository. – user237251 Jan 17 '18 at 09:04
  • What's the expected result? – C-Otto Jan 17 '18 at 09:04
  • I've edited my post. Thank you. – user237251 Jan 17 '18 at 09:05
  • Don't confuse `git pull` (the command verb) with "do things to files". The verb means *fetch, then run another Git command, merge by default*. You're asking to *avoid* merges so you don't want the `pull` verb. (This is aimed at both @C-Otto and user237251, who mentions specifically cherry-picking.) – torek Jan 17 '18 at 09:06
  • 1
    So you want the same result as if doing `git pull` and removing the commits that do not change `fileA` from your history? One consequence is that this altered history is incompatible with the server you pull from, so pushing back to it might be an issue. – C-Otto Jan 17 '18 at 09:07
  • Oh. I know what git pull does. I work with it daily. It's just really a use-case I never had to deal with and sort of difficult to describe for me. I'll update the OP with a description of my current workflow to make it more obvious. – user237251 Jan 17 '18 at 09:08

2 Answers2

0

Branches come to mind regarding this.

The purpose of the branch is simply that: to have a string of commits regarding a specific flow of development leading in a particular direction. Then, if it is desired that the development done in that branch is to be made part of the main project, the branch is merged. Else it is deleted.

Your best bet is to just do a git pull on the branch that contains that file.

cst1992
  • 3,823
  • 1
  • 29
  • 40
  • The parent project isn't under my control and generally doesn't expose all feature branches to the public (or they may, in fact, only exist on a developer's local machine). – user237251 Jan 17 '18 at 09:11
0

This solution is fairly close to what I want (only with folders instead of files. Although, as I just found out,that might be a saner approach anyways).

https://stackoverflow.com/a/32082356/3628813

This will get you the list of commits to master in tools/my-tool (that are not already in featureA), in reverse-chronological order:

git log --no-merges featureA...master tools/my-tool

To say it another way:

git log --no-merges source_branch...dest_branch my/firstpath my/secondpath [...]

To get just the commits you need in chronological order, you need to first reverse the order of the input lines (such as with tail -r or tac), then isolate the column for the commit hash (such as with cut):

git log --format=oneline --no-merges featureA...master tools/my-tool \ | tail -r \ | cut -d " " -f 1

And to do the whole operation at once, do this:

git cherry-pick $(git log --format=oneline --no-merges featureA...master tools/my-tool | tail -r | cut -d " " -f 1)

user237251
  • 211
  • 1
  • 10