'What are the git commands for the following steps?

I've created a branch A from master branch and checked out this branch, and worked in directory subdir_x only for a long time.

I will use the following steps to update master branch via pull request.

  1. Copy subdir (only the added and updated files) to a temporary location, e.g. /tmp/subdir_x.
    cp /path/to/..../subdir_x /tmp/subdir -r  # then remove unchanged files
  1. Create a branch B from master branch
    git checkou B
  1. Checkout B, copy /tmp/subdir_x to subdir_x (overwrite the old files)
    cp /tmp/subdir_x /path/to/..../subdir_x -r

(The pull request merging shows that it will revert some (not all) changes of some files not in subdir_x, very strange)

  1. Commit and push (then create Pull Request B -> master)

Are there any git commands which can be helpful in this case?


For example, I have the following files.

dir1/
    file1
    dir2/
        file2
dir3/
    file3
dirx/
    dirx1/
        filex1  # updated
        filex2  # no change
        dirx11/
            filex11  # no chnage
            filex12  # added
dir4/

I created a branch A from master, and have been working in dirx. And created a lot of commits. And filex1 was updated and filex12 was added. (At the same time, other people may have changed/added files and committed and merged to master)

Now I create a branch B from master, I want to apply all the commits (updated filex1 and added filex12) to B.

git


Solution 1:[1]

Since you have a PR (Pull Request) in progress for B, and A has new commits, all you need to do (assuming you are alone working on B) is:

git switch B
git rebase A # resolve potential merge conflicts there
git push --force

That will update your current PR, which will include all A commits and current B commits (now replayed on top of A)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC