Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I am having trouble with a Git conflict. I made some (uncommitted) changes on my local repo forked from another project. I then decided to fetch changes from the original repo - it told me I had to stash changes, which I did. Now when I try to "git stash pop" it says there is a conflict with one file, because it has changes from upstream plus my own changes.

What I want to do is actually keep the upstream changes, AND keep my own changes. I feel this has an obvious answer but its not clear for me.. I've looked up several similar questions on Stackoverflow, but couldn't find an exact solution.

My guess is I have to manually change the file in Sublime Text (OR do a hard reset?) but I'm not sure how to approach it.. For example, the parts that say "<<<< updated upstream" etc. are confusing to me - do I delete them in Sublime Text?? I am a bit nervous about messing it up, especially as I want to keep all changes (upstream plus my changes) and don't want to lose anything.

This is part of the file in Sublime Text showing the conflict:

<<<<<<< Updated upstream

    <>

      <GithubLink color={values.bgColor} />

      <Wrapper>

        <Output values={values} />

        <ActionWrapper>

          <InputWrapper values={values} setters={setters} />

        </ActionWrapper>

      </Wrapper>

    </>

=======

    <Wrapper>

      <Output values={values} />

      <ActionWrapper>

        <InputWrapper values={values} setters={setters} />

        <Dropzone onDrop={acceptedFiles => console.log(acceptedFiles)}>

           {({getRootProps, getInputProps}) => (

              <section>

                 <DropZoneDiv {...getRootProps()}>

                    <input {...getInputProps()} />

                    <p>Drag 'n' drop some files here, or click to select 

                    files</p>

                 </DropZoneDiv>

              </section>

            )}

        </Dropzone>

      </ActionWrapper>

    </Wrapper>

>>>>>>> Stashed changes

I edited this slightly to make it more readable, but basically you can see that the upstream has an added <\GithubLink> tag and my changes have an added <\Dropzone> tag - I want to keep both.

Thanks in advance!

1 Answer

0 votes
by (41.4k points)

The text shown between <<<<<<< Updated upstream and ======= is the version that was modified on the remote, while the text between ======= and >>>>>>> Stashed changes are your changes.

What you have to do at this point is figure out how to integrate your own changes and those on the remote into something coherent. Git cannot do it for you, because the same block was modified on both sides. That merge requires your analysis as a programmer. So replace everything between <<<<<<< ... and >>>>>>> ... with what you think is correct, remove the conflict markers, make sure you test the results, and that's the resolved conflict.

Also, check out this Git Tutorial to know more.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...