Remember a git problem encountered in a project

foreword

Because I was working on a project in school before, I didn't have too much contact with git, and the project didn't have much uninterrupted demand, so basically there were few branches established during development, and I was not familiar with branches, which led to a problem today. .

problems encountered

what I did the other day

A few days ago, there was a requirement to create a new branch a on the master branch of the project.
Specific method: clone the master branch of the project to the local git clone 远程地址, the default is to clone the master branch of the project to the local, then create a new branch add in the master, and switch to this branch, git checkout -b addand then submit after finishing the work on this branch:

git add .
git commit -m"xxxx"
git push origin add

At this time, I have my add branch remotely, so I still need to merge, because it is a project during the internship, so the merge request is made on the remote, and then the department boss will merge, and then it's ok.

Then here comes the problem

Because I'm used to cloning once, I'm not used to going to remote clone again. Today, another requirement was raised from the product side, so I got used to it, so I worked directly in the file directory I cloned from the remote a few days ago.
What is the specific work

  • This time the requirement is to create a new branch bb directly under the master branch for workgit checkout -b bb
  • Work under the bb branch, and after the work, submit:

    git add .
    git commit -m"xxxx"
    git push origin bb
    Problem analysis: Because the boss merged the add branch I made into the remote master branch before, so after doing the above work, the local master branch is different from the remote master branch at this time, so if the remote bb Conflicts will occur when the branch and the master branch are merged.
    problem solved:
  • Switch to the local branch master and merge the remote branch master into the local mastergit pull origin master
  • Then switch to the bb branch, git rebase masterand finally cancel each commit (commit) in your "bb" branch, and temporarily save them as patches (the patches are placed in the ".git/rebase" directory ), then update the "bb" branch to the latest "master" branch, and finally apply the saved patches to the "bb" branch.
  • git push -f origin bbAt this time, it will be modified and pushed to the remote bb branch, and finally the bb branch will be merged into the master.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325852075&siteId=291194637