假设我有2个分支,master
和other
。
我进入other
分支,添加2个文件,提交并推送。
现在,我进入master
分支,将文件添加到其他目录,然后提交它们。然后,我 merge other
。
问题是我在other
中添加的文件没有显示。 Git说它是最新的,但事实并非如此!文件丢失。
如何强制master
在other
中添加文件或以某种方式手动添加它们?
为Karl编辑:
我尽我所能进行了以下操作,尽管未显示的更改已有几周的历史了。我只是意识到他们今天不在那儿。
$ git branch
*other
master
$ git add .
$ git commit -m 'cool new features'
$ git push origin other
$ git checkout master
$ git merge other
$ git add .
$ git commit -m 'merged cool new features from other'
$ git push origin master
我继续使用Github,但文件不存在。其他文件已提交并显示,但是两个文件夹没有匹配的内容。这些文件以
other
存在,但不存在于master
中。要澄清的是,这些文件不是新的。但我认为, merge 将至少将文件复制到master
,如果它们不存在! 最佳答案
像这样:
karl@Bielefeldt-Server:~/stackoverflow$ git init .
Initialized empty Git repository in /home/karl/stackoverflow/.git/
karl@Bielefeldt-Server:~/stackoverflow$ touch common_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch common_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit common files"
[master (root-commit) 89a5cd0] commit common files
0 files changed
create mode 100644 common_file_a
create mode 100644 common_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git checkout -b other
Switched to a new branch 'other'
karl@Bielefeldt-Server:~/stackoverflow$ mkdir other
karl@Bielefeldt-Server:~/stackoverflow$ touch other/other_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit other files"
[other 9c7409c] commit other files
0 files changed
create mode 100644 other/other_file_a
create mode 100644 other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git checkout master
Switched to branch 'master'
karl@Bielefeldt-Server:~/stackoverflow$ touch master_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit master files"
[master 3558768] commit master files
0 files changed
create mode 100644 master_file_a
create mode 100644 master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ ls
common_file_a common_file_b master_file_a master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git merge other
Merge made by the 'recursive' strategy.
0 files changed
create mode 100644 other/other_file_a
create mode 100644 other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ ls
common_file_a common_file_b master_file_a master_file_b other
karl@Bielefeldt-Server:~/stackoverflow$ ls other
other_file_a other_file_b
如果获得不同的结果,则可能是缺少一个步骤,或者在某个地方增加了一个步骤,或者出现了一些您没有告诉我们的错误,例如 merge 冲突。除非像我上面那样发布确切的命令和输出,否则我们无法知道为什么如此基本的东西对您不起作用。
关于 merge 后,git master分支根本没有新文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13618108/