创建git分支并提交到单独的分支

时间:2022-09-04 11:03:54

noob to git:
expanding on this question a little

noob to git:稍微扩展这个问题

I created a repository and committed my README.md to the master branch.
My local folder structure is:

我创建了一个存储库并将我的README.md提交给master分支。我的本地文件夹结构是:

projectName  
 --README.md  
 -- + part1  
 -- -- README.md  
 -- -- + src  
 -- + part2  
 -- + ...  

I initialized git init in the projectName folder and was able to make the commit.

我在projectName文件夹中初始化了git init,并且能够进行提交。

Then I do git checkout -b part1.
cd .\part1 and git add .\README.md .\src

然后我做git checkout -b part1。 cd。\ part1和git add。\ README.md。\ src

When I commit and push git push -u origin part1 and check my repository my master branch has all the files from part1 and the part1 branch has correct files but it contains the README.md from the master branch.

当我提交并推送git push -u origin part1并检查我的存储库时,我的master分支包含part1中的所有文件,part1分支具有正确的文件,但它包含来自master分支的README.md。

After I 'remove' the master README.md I want to commit from branch part1 the files/folders in my local part1 folder. The problem I am having with this is when I commit the actual folder part1 shows up in the part1 branch. I just want the contents to show up.

在我'删除'主README.md后,我想从分支part1提交我本地part1文件夹中的文件/文件夹。我遇到的问题是当我提交实际文件夹part1显示在part1分支中时。我只想要显示内容。

EDIT_1
I want to create multiple branches. After committing to the master branch I do this:
git checkout -b part1
When I commit from part1 I don't want the README.md from the master coming along for the ride. Doing git rm README.md deletes the file from my local directory.

EDIT_1我想创建多个分支。在提交到master分支后,我这样做:git checkout -b part1当我从part1提交时,我不希望来自master的README.md出现。执行git rm README.md会从我的本地目录中删除该文件。

UPDATE
I was confused about the second part of my own question. @willoller clarified.

更新我对自己问题的第二部分感到困惑。 @willoller澄清道。

1 个解决方案

#1


1  

Use the following command git checkout -b new_branch to create a new branch from current branch.

使用以下命令git checkout -b new_branch从当前分支创建新分支。

So you created your part1 from master and your README.md was copied from master.

所以你从master创建了part1,你的README.md是从master复制的。

"-u" creates a relation with remote branch.

“-u”与远程分支创建关系。

If you want push your branch to remote host, you could just use git push origin my_branch.

如果你想将你的分支推送到远程主机,你可以使用git push origin my_branch。

To delete files from branch use git rm and commit the changes afterwards.

要从分支中删除文件,请使用git rm并在之后提交更改。

I hope I've helped.

我希望我能帮到你。

#1


1  

Use the following command git checkout -b new_branch to create a new branch from current branch.

使用以下命令git checkout -b new_branch从当前分支创建新分支。

So you created your part1 from master and your README.md was copied from master.

所以你从master创建了part1,你的README.md是从master复制的。

"-u" creates a relation with remote branch.

“-u”与远程分支创建关系。

If you want push your branch to remote host, you could just use git push origin my_branch.

如果你想将你的分支推送到远程主机,你可以使用git push origin my_branch。

To delete files from branch use git rm and commit the changes afterwards.

要从分支中删除文件,请使用git rm并在之后提交更改。

I hope I've helped.

我希望我能帮到你。