简体   繁体   中英

GIT branch not merging

I have three branches:

*branch_a
main
master

tied to a remote repository. i am currently on the branch_a branch, which has differences from the remote main branch: origin/main. that is, the remote origin/main has a file named 'file.txt' with the letter 'A' as the only character, whereas my local branch, branch_a, has the same file, 'file.tx' with the letter 'B' as the only character. I can see these differences while checked out in the branch_a; using:

git diff origin/main

however, when i try to merge theses changes, that is merge from the remote origin/main, i am getting:

Already up to date.

I'm not sure how come the changes are not showing up and merging from the remote origin/main to my local branch, branch_a.

You are not giving enough information to know the reason, but it's easy to give a reason. Let's say you did this:

  1. On main , create the file file.txt with content A.

  2. Add and commit and push.

  3. Create branch branch_a and switch to it.

  4. Edit the file file.txt to have content B.

  5. Add and commit.

Now you will see the same phenomena you just described. origin/main and branch_a show a diff for file.txt , but you cannot merge origin/main into branch_a . This is because branch_a is ahead of origin/main . It is origin/main plus an additional commit, and that's all it is. There is nothing to merge, because branch_a already "has" all the same commit(s) that origin/main has.

But now do this:

  1. Switch back to main .

  2. Create another file, add it, commit, and push.

  3. Switch back to branch_a and try the merge again.

Now you will be able to merge because there is something to do .

Are you trying:

git add file.txt
git commit -m "your comment here"
git push 

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