Обратите внимание, что в принятом ответе первый вариант ставит весь файл из другой ветви (как был выполнен git add ...
), и что второй вариант просто приводит к копированию файла, но не вносит изменения (как если бы вы только что отредактировали файл вручную и имели выдающиеся различия).
Git скопировать файл из другой ветки без его постановки
Постановка изменений (например, git add filename)
:
$ git checkout directory/somefile.php feature-B
$ git status
On branch feature-A
Your branch is up-to-date with 'origin/feature-A'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: directory/somefile.php
Изменения ожидают (не организовано или не совершено):
$ git show feature-B:directory/somefile.php > directory/somefile.php
$ git status
On branch feature-A
Your branch is up-to-date with 'origin/feature-A'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: directory/somefile.php
no changes added to commit (use "git add" and/or "git commit -a")