0

I have a git repo to store my "dot files" and I have a branch that I use in company's computer and another one that I use in my personal one.

Often I create useful functions and aliases at work that I would like to use on my personal computer. However, I would like to only copy these functions while avoiding having copy certain environment variable. Or sometimes I may just need to tweak the function because I use different folder structures at work and at home.

To give an idea of what I want, if I was using SVN (and assuming I had a folder per branch) I would just compare my two branch folders (with meld, for instance) and I would just manually copy things between the two versions of the file (one for each branch).

My question is: would I be able to do this with git? Neither merge nor cherry-pick seem to be fit for purpose for what I want.

Thanks.

  • do you want to copy over entire file from another branch? – Thiru Jul 07 '18 at 12:06
  • Hi @Thiru. No, just some lines and I want to have the flexibility to choose the lines I want. Thanks for asking. –  Jul 08 '18 at 19:47

2 Answers2

0

The following command will show you one file in difference branch side-by-side in diff tool, then you can compare and edit them at your will.

git checkout you_personal_branch
git difftool your_work_branch..you_personal_branch -- path_to_file_you_want_to_edit

The file of your personal branch will show on right panel of your diff tool, it is in your current work directory, so you can edit it.

About how to make 'git difftool' launch meld, you can see Setting up and using Meld as your git difftool and mergetool

gzh
  • 3,507
  • 2
  • 19
  • 23
  • Thanks, this kind of works, but I think I always need two apps: the "diff tool" to highlight the differences and a text editor where I would paste whatever I need from my work branch. If I use a diff tool like meld, I can copy things around and click Save. However, when I close meld the end changes are lost. It's as if meld is saving things into a temporary file. Not sure if I'm making sense or being clear. –  Jul 07 '18 at 19:41
0

To copy a specific file from one branch to another instead of merging and cherry-pick entire commit, you could the following command:

git checkout <branch_name> <file_name_1> <file_name_2>

This will help in copying the files from another branch to the current branch

Thiru
  • 2,541
  • 4
  • 25
  • 39