在我执行git add和commit两个文件(model.R和preprocessing.R)之后的git状态:
Macs-MacBook:crime_type_class_mlmodel macuser$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 2 and 9 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: 20170628_somefile.txt
deleted: model.R
deleted: somecsv.csv
deleted: somecsv1.csv
modified: rscripts/.RData
modified: rscripts/.Rhistory
modified: rscripts/preprocessing.R
deleted: somecsv2.csv
Untracked files:
(use "git add <file>..." to include in what will be committed)
.DS_Store
.RData
.Rhistory
database snippets.sql
output_csvs/
我试图将我的本地目录中的两个文件提交到github。
git push origin master
To https://github.com/ourco/myprojectrepo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/ourco/myprojectrepo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
所以,我按照消息的建议尝试了git pull:
Macs-MacBook:crime_type_class_mlmodel macuser $ git pull origin master
From https://github.com/ourco/myprojectrepo.git
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
rscripts/.RData
rscripts/.Rhistory
Please, commit your changes or stash them before you can merge.
Aborting
当我在浏览器中访问时,这两个文件.RData和.RHistory不会显示在回购中。我不想在github中使用它们,我也不想在本地覆盖它们。这两个文件应该只在我的本地目录上。所以,我担心会覆盖它们。
如何将model.R和preprocessing.R文件同时提交给github?
答案 0 :(得分:2)
将这些文件添加到.gitignore
,然后git不会关心对它们所做的更改,从而不会抱怨冲突。
此外,您可以暂时存储它们:
git stash save
然后执行merge / rebase / pull
git stash pop
他们又回来了。
此外,如果你发现其他人正在将它们添加到回购中(通过做一个顽皮的git add -a
或git add .
,而不是使用交互式git add -p
标志)那么你应该使用更改将.gitignore
提交到repo。不幸的是,您需要按步骤执行此操作,因为已经跟踪了这些文件:删除文件,提交删除,推送,更新.gitignore
,提交&amp;推送它,然后在本地恢复文件。让你的其他开发者知道他们应该支持他们。