32

I was merging master branch into new branch, there are some .rej files are created.

I took a pool of master branch into new branch I got conflicts which I've resolved but there are some .rej files.

Can you please help me to know about the .rej files and what am I suppose to do with those files.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
GajanaN Chalke
  • 517
  • 1
  • 5
  • 13
  • They are rejection files, describing "failing" merges; you certainly need to look into them. – Basile Starynkevitch Jan 04 '16 at 06:37
  • The steps that I've followed are correct or wrong? Actually development was going into Master but for new UI changes new Branch was created mean while some changes has been made into master, so to reflect those changes I took a pool of Master into new branch and I got conflict which I've already resolved but not able to understand about the .rej files. Can you please explain a little bit about failure and cause ? – GajanaN Chalke Jan 04 '16 at 06:41
  • Did you look *inside* some `.rej` file? Read https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/ – Basile Starynkevitch Jan 04 '16 at 06:42

2 Answers2

44

.rej files are rejected files (usually hunks patches but not only).

When ever you get those files after merge you will manually have to edit them, fix them and then apply them back.

You can read here some more about it and what is it

.rej file

diff a.txt    (rejected hunks)
....

Fix it manually and then apply the .rej files like a regular patch.

manually merge the change from *.rej into the required file and remove the *.rej file.

Another very usefully article addressing this can be found here.

romellem
  • 5,792
  • 1
  • 32
  • 64
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I checked the file from both i.e. from master & new branch using beyond compare tool, actually there is no difference not even blank line, in such a case .rej file should not be created, right? Then why .rej file is created? is there any step I missed while merging master into new branch? #I'm using SourceTree for UI. – GajanaN Chalke Jan 04 '16 at 10:03
  • No. `.rej` files should be created when there is a problem only – CodeWizard Jan 04 '16 at 10:07
  • Thanks a lot @codeWizard, it worked! I merged the branches successfully. Is there any better way(if the way I merged the branches is wrong) to merge the master branch into newly created branch? – GajanaN Chalke Jan 04 '16 at 19:06
  • A better way to merge? depends on several things, how many commits, how many branches, basically - merge often as much as you can to avoid conflicts. you can do a git pull every hour – CodeWizard Jan 04 '16 at 19:39
  • 1
    @codWizard Thanks a lot. – GajanaN Chalke Jan 04 '16 at 20:21
  • Np. fell free to read some of my other answers as well and vote for them if you find something new in them. – CodeWizard Jan 04 '16 at 20:22
  • 3
    I guess I can simply solve conflicts manually, and then ignore all .rej files? – Ben Carp Jan 16 '18 at 14:39
  • @CodeWizard hi, thanks for your answer. I still don't understand how to edit these .rej files. Maybe there was information in the link you provided - but it appears to be broken. – manish ma Apr 27 '21 at 09:32
  • Hey thanks for the info! I think it's slightly confusing for the line `Fix it manually and then apply the .rej files like a regular patch` and `manually merge ....`. It gives impression that after `.rej` is created, we have an option to do `git apply` with that `.rej` again, or manually do the merge from diff in `.rej` ourselves. The article you linked in did the latter way though. Anyway, thanks for info! +1 – haxpor Aug 07 '21 at 13:35
-2

Since I knew that my remote master branch was up to date, I just deleted all the .rej files and then did git pull.

Marlo
  • 490
  • 3
  • 7
  • 21