开发者

How to add a file to a particular branch in git?

开发者 https://www.devze.com 2023-03-16 22:18 出处:网络
I am doing some sample test with git, before i add my actual stuff. Here is what i do: enter code here 1) Create an empty git repository

I am doing some sample test with git, before i add my actual stuff.

Here is what i do:

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 br开发者_如何学Canch1 (Create a branch1 inside this git)
$ touch File1
$ echo "This is a test" >> File1

Now i want to add File1 to branch1. How to do this?


you can just

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

and File1 will only be in branch1


Well we really need to know what your mysterious cg-branch-add command does, but assuming that it just adds a branch with git branch then you will need to start by switching to that branch:

git checkout branch1

then add the file:

git add File1

and commit it:

git commit
0

精彩评论

暂无评论...
验证码 换一张
取 消