How to merge branches in Git using "hunk"

Here is the script. I made the dev branch on the master branch and made some new commits. Some of these changes will only apply to my local development machine. For example, I changed the URL variable to point to the local apache server instead of the real URL published on the Internet (I did this for speed at the testing stage). Now I would like to include my changes from the dev branch into the main branch, but NOT those changes that make sense only in my local environment.

I would anticipate something like a --patch merge that would allow me to select the changes that I want to merge line by line.

Alternatively, maybe I can check the "master" branch, but save the files in my working directory as they were in the "dev" branch, and then do git add -patch. Will this work?

+6
source share
2 answers

One approach is to merge the changes with another branch, but before merging, delete the content that is specific to the development.

First get the changes without binding them to git merge --no-ff --no-commit dev .

Remove development-specific changes, either by editing the affected files, or git add them, or git reset HEAD affected files, and then git add --patch the parts you want.

Then copy the merge. The advantage of performing a merger is that future mergers will be painless. Since development-specific commits are considered merged, future merges not related to specific parts can be performed using a simple git merge dev . Thus, you can unlimitedly maintain a separate branch with its own configuration, while at the same time seamlessly merging with the changes in the leading branch.

+6
source

Perhaps you could try something like this?

 git merge --squash --no-commit $YOUR_OTHER_BRANCH git reset HEAD git add -p git commit 
+2
source

Source: https://habr.com/ru/post/912549/


All Articles