Git ① Merge two local projects through git

1. Create a new local warehouse

① Create a new folder, open it and enter git init  on the command line to initialize the warehouse.

git init

② Create a file in the newly created folder (this will create a new branch, otherwise the new branch command will have no effect)

③ Enter the commands git add .   and   git commit -m "init" to initialize the warehouse.

git add .
git commit -m "init"

2. The main branch stores code A, and a new branch is created to store code B.

① Enter the command git checkout -b sub to create a branch named sub

    Then enter the command git checkout master to switch the branch back to the master branch.

git checkout -b sub
git checkout master

 ② In the master branch, put code A.

③ Use git add. and git commit -m "initialize A code" commands to submit the code.

git add .
git commit -m "初始化A代码"

④ Use the command git checkout sub to switch to the secondary branch, and also put code B into the sub branch.

git checkout sub

 ⑤ Use git add . and git commit -m "initialize B code" command to submit the code.

git add .
git commit -m "初始化B代码"

 ⑥ Use git checkout master to switch to the main branch

 git checkout master 

⑦ Use git merge sub to merge the contents of the sub branch with the main branch, and then resolve the conflict.

git merge sub

⑧ After resolving the conflict, use the command to merge the codes of the two projects.

 

 

 

Guess you like

Origin blog.csdn.net/zujiasheng/article/details/131565889