1

This might sound like a similar question to this, but it isn't because my question focuses on the need to push a single file from within a larger commit to another branch.

I have a file, script.R, which I have committed and pushed to the mus branch along with several other files which have been modified in some way.

I now want to push just this file (script.R) to the group branch as it currently stands.

I haven't made any further changes to script.R, nor any other files, since the last commit and push to the mus branch, meaning that git status shows nothing to update.

Given this information, is what I want to do possible?

I hope that this explanation is clear, but if not I am happy to adapt the question to make it clearer.

Mus
  • 7,290
  • 24
  • 86
  • 130

1 Answers1

2

You cannot "push"/merge only 1 file of an existing/bigger commit/revision in Git.

The solution for your situation is taking this 1 file-version to your branch and recommitting it. This is basically just copying, meaning when you merge the branches together later there will be some redundancies as the history is not shared.

It can be done with git checkout: Being on the group branch:

git checkout mus -- script.R
git add script.R
// commit/push

See also: How to get just one file from another branch?

Tobias K.
  • 2,997
  • 2
  • 12
  • 29