如何在git中将文件添加到特定分支?

时间:2011-06-30 10:59:50

标签: git cg

在添加实际内容之前,我正在使用git进行一些示例测试。

这就是我的所作所为:

enter code here
1) Create an empty git repository

$ mkdir git_trial2
$ cd git_trial2
$ git init (Creates a .git directory inside this)
$ cg-branch-add branch1 (Create a branch1 inside this git)
$ touch File1
$ echo "This is a test" >> File1

现在我想将File1添加到branch1。怎么做?

2 个答案:

答案 0 :(得分:1)

你可以

git checkout branch1
git add File1
git commit -am "added File1"
git checkout other_branch

和File1只会在branch1

答案 1 :(得分:1)

我们真的需要知道你的神秘cg-branch-add命令是做什么的,但假设它只是添加了git branch的分支,那么你需要从切换到该分支开始:

git checkout branch1

然后添加文件:

git add File1

并提交:

git commit