在git中的特定分支上添加文件

pra*_*bhu 4 git github

我是git的新手,希望能正确使用它.

git init
git add .      // added the whole directory
git commit -m "initial stage"
git checkout -b "version1"
git branch

  master
* version1
Run Code Online (Sandbox Code Playgroud)

现在我想在目录中添加一些新文件

cp /path/to/file/admin.php /path/to/git/folder/.
Run Code Online (Sandbox Code Playgroud)

这些文件应仅包含在version1分支上,但它也包含在master分支中

git add admin.php
git status
On branch version1
Untracked files:
(use "git add <file>..." to include in what will be committed)
admin.php

git checkout master
git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
admin.php
Run Code Online (Sandbox Code Playgroud)

问题是如何才能在特定分支上添加文件?

谢谢

小智 13

要在特定分支中添加文件,请遵循以下说明:

创建自定义分支

git branch branchname
Run Code Online (Sandbox Code Playgroud)

切换到自定义分支

git checkout branchname
Run Code Online (Sandbox Code Playgroud)

在自定义分支中初始化

git init
Run Code Online (Sandbox Code Playgroud)

在自定义分支中添加文件

git add file name
Run Code Online (Sandbox Code Playgroud)

提交自定义分支中所做的更改

git commit -m "your message"
Run Code Online (Sandbox Code Playgroud)

在GitHub仓库中进行更改

git push
Run Code Online (Sandbox Code Playgroud)

希望你得到明确的想法.

谢谢.