简体   繁体   中英

How to merge current branch into master locally, with conflicts, ignoring changes in master?

Hi I was trying to merge my current branch into master, but it said I have merge conflicts.

I tried so many answers but none of them have been able to solve my problem. The steps given by gitlab also don't seem to work.

I tried rebasing, checking out and what not. I have ended up with detached heads, and loads of things I don't really understand. What I want to know is, how to merge by current branch, named test into master. I don't care what is there in master. I just want to merge exactly what's there in my current branch into master. Can anyone help me?

What steps should I follow after I do

git clone test link

If you really don't care what's in master (eg other work in master you or other developers have done will be "lost", and history will be changed), then:

git checkout master
git reset --hard your-branch-name

What this does

Before:

* B1 <- [your-branch-name]
| * C2 <- [master]
|/
* C1

After:

* B1 <- [your-branch-name][master]
| * C2 ("lost")
|/
* C1

Changes in C2 will be "lost" -- it will still exist in temporary backup for a while, but has no named branch pointing to it anymore (and will be garbage collected at some point)

History will be changed -- in the "After" state, it'll seem like master never had changes in C2 to begin with.

Please first check git status to see which files you have changed.

The use git merge to see the files which could be overwritten.

then remove them using

rm filename

and then

git merge.

With git merge

  1. Merge master into your test branch first
    git checkout test
    git merge master
    // fix the conflict code
    git commit -am "merge with master"
  1. Then merge test into master
   git checkout master
   git merge test

With git rebase

  1. Rebase master on test
    git checkout test
    git rebase master
    // fix the conflict code
    git commit -am "merge with master"
  1. Merge test into master
    git checkout master
    git merge test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM