I have a git repository with two branches: master and gh-pages. If I want to copy a file foo from master to gh-pages without merging them. What command should I use? Many thanks.
Asked
Active
Viewed 3.7k times
55
Chongxu Ren
- 1,537
- 2
- 13
- 14
4 Answers
83
You can:
git checkout gh-pages
git checkout master foo
git commit -m 'Add file foo to gh-pages.'
cforbish
- 7,977
- 2
- 27
- 31
-
3Yes, thank you, but it seems that `foo` file must be commited first. But it works fine. Thank you. If I have enough reputations, I'll vote up you~ – Chongxu Ren Jul 02 '13 at 03:10
-
3Of course it has to be committed first—otherwise it's not "on that branch", it's just in your working copy. If that is the case, you should use `git stash`. – Wildcard Dec 02 '15 at 22:33
-
Or, if it is uncommitted, just checkout the desired branch. The uncommitted change will stay with you ready checkin. – Tormod Sep 21 '17 at 05:34
2
If you want to compare all the diffs between 2 branches: you can use git difftool master gh-pages or git difftool <SHA1 of gh-pages> .
If you want to get diff for specific list of files follow this:
git diff master gh-pages -- path/to/file
-
It doesn't work fine, it will show all files different between the two branches. It can be very annoying. Thank you all the same. – Chongxu Ren Jul 02 '13 at 03:12
0
Also may do cherry-pick from master to gh-pages after commit foo.(After cherry-pick must execute git add [path to foo] and commit)
Alexandr
- 13
- 3
-1
The Way I would do it: When you commit you have a choice of what to commit and push. So commit only foo from master then push it, Then just merge that on github/bitbucket whatever to gh-pages
dsuma
- 1,000
- 1
- 9
- 29
-
Only commit `foo`? It's a useless commit. That will force others pull it and make them annoyed. It is worse than using `cp` command. – Chongxu Ren Jul 02 '13 at 03:00
-
Errrr~~ I'm sorry I didn't understand you clearly. It seemed you meant I should merge `master` and `gh-pages`. Is that right? – Chongxu Ren Jul 02 '13 at 03:16