简体   繁体   中英

Git - checkout new commits from another branch

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 ?

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 .

You can do git cherry-pick <changeset hash> . Eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM