在git中的特定分支上添加文件
我是git新手,希望能正确使用它在git中的特定分支上添加文件,git,github,Git,Github,我是git新手,希望能正确使用它 git init git add . // added the whole directory git commit -m "initial stage" git checkout -b "version1" git branch master * version1 现在我想在目录中添加一些新文件 cp /path/to/file/admin.php /path/to/git/folder/. 这些文件应仅包括在版本1分支上,但也包括在主分支
git init
git add . // added the whole directory
git commit -m "initial stage"
git checkout -b "version1"
git branch
master
* version1
现在我想在目录中添加一些新文件
cp /path/to/file/admin.php /path/to/git/folder/.
这些文件应仅包括在版本1分支上,但也包括在主分支中
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
git add admin.php
git状态
关于分支版本1
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
admin.php
切换到主分支
git状态
论分行行长
未跟踪的文件:
(使用“git add…”包含在将提交的内容中)
admin.php
问题是我如何才能只在特定分支上添加文件
谢谢要在特定分支中添加文件,请按照以下说明操作: 创建自定义分支的步骤
git branch branchname
git checkout branchname
git init
git add file name
git commit -m "your message"
切换到自定义分支
git branch branchname
git checkout branchname
git init
git add file name
git commit -m "your message"
在自定义分支中初始化
git branch branchname
git checkout branchname
git init
git add file name
git commit -m "your message"
在自定义分支中添加文件的步骤
git branch branchname
git checkout branchname
git init
git add file name
git commit -m "your message"
提交在自定义分支中所做的更改
git branch branchname
git checkout branchname
git init
git add file name
git commit -m "your message"
在GitHub回购协议中进行更改
git push
希望你有明确的想法
谢谢你。有时当你使用
git add fileName
你得到了这个错误
以下路径被一个.gitignore文件忽略:
文件名
要继续添加它,请转到.gitignore并注释与该文件相关联的行添加#
然后您将能够添加、提交和推送。该文件在两个分支上都不存在;用git术语来说,它是“未跟踪的”。在
git add
和git commit
之前,它将继续不存在于存储库中的任何位置,只存在于您的工作目录中。你需要从一些。。。(*从技术上讲,git add
会将其保存为临时内容,但在git commit
步骤之前,它不会成为永久内容。)@torek您的评论正是答案。那么为什么不回答呢?@torek说了些什么,但是有了更多的信息和更多specific@RomanGotsiy:主要是因为完整的答案会花费太长时间,并且与其他现有的SO答案和Pro Git书籍重复。这个问题暴露了对git的根本误解。