Home > Net >  How to push every single file change in separate merge request
How to push every single file change in separate merge request

Time:04-02

I have a few files:

tasks/foo1
config/foo2
foos/foo3

I made changes to every single one of them and I have two commits with changes to all of them in every single one. How do I make seperate mr's for them? I mean 1 mr -> 1 file changed

CodePudding user response:

MRs simply contain commits. In order to achieve this, you would, at a minimum, need each of your commits to only include changes to one file. With the scenario you describe, you would have to undo (reset) your two commits that edited the three files then re-perform the commits adding the file changes one by one. This is a history rewrite.

Suppose you are currently on your edited branch with the two commits that edited the three files. You could create 3 new branches (from which 3 new MRs will be made for each file) and rewrite the history accordingly:

git branch edit-file1
git branch edit-file2
git branch edit-file3

# checkout the branch where HEAD contains your two commits
git checkout edit-file1

# reset the two commits, unstaging changes to 3 files
git reset HEAD~2

# add and commit just 1 file
git add path/to/file1 
git commit -m "edited file 1"

# push new branch and make MR
git push -u origin edit-file1 -o merge_request.create 

# do the same thing for file 2
git checkout edit-file2
git reset HEAD~2
git add path/to/file2
git commit -m "edited file 2"
git push -u origin edit-file2 -o merge_request.create

# and for file 3
git checkout edit-file3
git reset HEAD~2
git add path/to/file3
git commit -m "edited file 3"
git push -u origin edit-file3 -o merge_request.create

Though, it would probably just be easier if you never made the first two commits to begin with and originally just add and commit the files one by one.

CodePudding user response:

Depending on whether you want the three changes in series or parallel,

git reset --soft @~2     # back up over the last two commits
git commit -o tasks/foo1    # make three commits in series, adding one file each time
git commit -o tasks/foo1 config/foo2
git commit -o tasks/foo1 config/foo2 foos/foo3

or

git reset --soft @~2
git commit -o tasks/foo1;  git branch foo1merge
git reset --soft @~
git commit -o config/foo2; git branch foo2merge
git reset --soft @~
git commit -o foos/foo3;   git branch foo3merge

and that'll get you one mergeable branch for each of the three changed files. If you then want to continue.

  • Related