'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.
- 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
- Create a branch
Bfrom master branch
git checkou B
- Checkout
B, copy/tmp/subdir_xtosubdir_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)
- 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.
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 |
