1

I have a git repository like this

    .
├── a.py
├── __init__.py
├── data
│   ├── a_data.yaml
├── configs
│   ├── a_config.txt

I have created a branch and worked on creating a package. So it looks something like this now.

.
├── LICENSE.txt
├── MANIFEST.in
├── Makefile
├── README.rst
├── VERSION.ini
├── __init__.py
├── requirements.txt
├── scripts
│   ├── a
├── setup.py
└── a_package
    ├── a.py
    ├── __init__.py
    ├── config
    │   ├── __init__.py
    │   ├── a_configs.txt
    ├── data
    │   ├── __init__.py
    │   ├── a_data.yaml

While I was packaging and working on my branch, there were changes that got pushed onto "a.py". So my question is using git how can I pull the changes from origin since the directory has changes.

Ani
  • 149
  • 1
  • 1
  • 8
  • You would merge the changes ("pull" means "fetch and merge") the same way you merge any other changes, using `git merge`. Are you having the specific problem that Git is not identifying the original commit's `a.py` file with your own `a.py` file *and* with the latest commit's `a_package/a.py` file? If so, that's a solve-able problem, but you need to state that this is the problem. – torek Nov 13 '20 at 01:58
  • The problem here is I have some local modifications that I have pushed to remote for a.py. and master branch from where I have created my branch had some changes that went into it. So I need to reach to a position where my file structure is preserved and also get the changes in master for a.py reflected in a.py in "a_package" directory – Ani Nov 13 '20 at 06:06
  • Well, remember that `git merge` is about merging work done since some common starting point. To achieve the effect of this merge, Git locates three commits. One is the common starting point. Git finds this itself. The second is your current commit. You choose which commit is the current commit, by checking it out (usually through a branch name). The third commit is someone else's, which you choose by what argument you pass to `git merge`. Git then compares the common starting point to both end-points. [continued] – torek Nov 13 '20 at 06:29
  • This comparison finds some files that are "the same files". Sometimes those files are files with the *same name*, such as `path/to/file.ext` in all three commits, but sometimes those are files with *different names*, such as `path/to/original` in the base, `path/to/original` in one of the two tip commits, and `new/name` in the other tip commit. – torek Nov 13 '20 at 06:31
  • In your case, you can hope that Git will identify (pair-up) the correct `a.py` files. If it does so, you're in great shape: Git already did what you want. If not, you have a question for Stack Overflow. (Note that this question appears multiple times on SO already, with multiple answers.) – torek Nov 13 '20 at 06:31

1 Answers1

0

I would try, if we are talking about a single file, to

That is:

cat patch_file | git am     \ 
         --directory='a_package/'     # prepend 'a_package/'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250