1

I use git to manage my dotfiles, I use both linux and mac osx so I create separate branches for these two and another master for the common settings.

When I edit something which is common and I want to save the changes to another branch. This is how I work at the moment:

git checkout master
git commit ...
git checkout arch
git checkout master <file1>
git checkout master <file2>

This is a lot of work. Can I checkout a commit instead of file, or is there any even shorter way than this ?

Dzung Nguyen
  • 8,760
  • 13
  • 61
  • 98

2 Answers2

2

Instead of cherry-picking (see its disadvantage here), I would rather merge master in the other branches.

See for instance "Git branches for working on dev while merging some changes into the master".
That way, you know what was already integrated into your branches from master.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • in arch branch for example, I have another arch folder which doesn't exist in master. So If I merge master in arch, this will delete that folder which is not what I want. But does I misunderstand something ? – Dzung Nguyen Jul 03 '12 at 08:43
  • 1
    @Vdt it shouldn't delete the directory, unless you had that directory in `master` first and deleted there. If you introduced that directory in your `arch` branch (so *after* branching from `master`), a merge from `master` won't touch it. – VonC Jul 03 '12 at 10:24
  • yes, it's exactly the situation I've been on. How can I avoid deleting these folders ? – Dzung Nguyen Jul 03 '12 at 10:46
  • 1
    @Vdt Then you might do the merge, then restore the directory. That merge will record a merge link between master and arch, and any subsequent merge won't touch the directory. – VonC Jul 03 '12 at 11:43
  • Thanks for your answer. I also love the idea of making thing work properly instead of dirty tips and tricks to make it work but not right ;) – Dzung Nguyen Jul 03 '12 at 21:08
1

You can do git cherry-pick <changeset hash>. E.g. git cherry-pick 1a15f41e2. This will apply the commit to current branch. If the commit exists only in remote repo you will have to do git fetch before cherry picking. Documentation: http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html

valentinas
  • 4,029
  • 18
  • 27