0

I am currently writing a text with R bookdown and asked two friends to read my text and give comments, corrections and general feedback. My source files for the text are stored on GitHub and I would like my collaborators to make changes in the files (one for each chapter) with the help of git. However, none of us are really experts on git. This makes it hard to figure out what a suitable workflow is.

For now, we decided that each one of them creates himself a branch so that he does not directly push into the master branch. After I have read their changes I would like to decide what I merge into the master branch and what not. So far, it looks like each change needs to be in a separate commit because I am not able to merge single lines from a specific commit (not sure if that is at all possible). However, this seems like a lot of annoying and unnecessary commits to create. So, I guess I am looking for a way to avoid that and/or general pointers towards a good workflow for such kind of projects.

AlbertRapp
  • 408
  • 2
  • 9

2 Answers2

0

A useful command will be git cherry-pick, it allows you to select specific commits from a branch.

A general good practice is that commits should be self contained (if applied alone they make sense) and they target a specific feature (in the use case mentioned, that could be a paragraph or a section or a chapter).

In the end, if you would like to apply only specific changes of a commit, that would have to happen manually, someone has to decide which parts to apply and which not. A commit can be edited using git rebase -i <branch name> before being merged. This question might also be useful.

Zois Tasoulas
  • 1,242
  • 1
  • 11
  • 23
  • This answer would work if every change is already separated into separate commits, however, the question is asking if it can be accomplished without so many commits. (If the answer is no, you can't do that, then this would be a possible way to go.) – TTT Feb 04 '21 at 22:07
  • @TTT is right. I am trying to avoid having to commit every line change. The way I understand it, `git rebase` seems to work on single files. However, all the changes of one chapter are within one file. Ideally, I would like all or a handful of commits per chapter. Thus, I would need to accept/decline line changes from those commits. I don't understand why this is not easily doable. When I have a merge conflict, this is exactly what I am able to do in gitkraken. See the diff of the two merged files and accept which line change to keep and which one to discard. – AlbertRapp Feb 05 '21 at 12:33
0

I finally found what worked for me in here. Basically, on my master branch I had to use

git merge --no-commit --no-ff branch-to-merge

This will merge all changes into my master branch but does not immediatly commit the changes so that they can still be staged/unstaged. Then, I can decide what line change to include by staging the line changes I want to keep and discard all other line changes. Finally, I commit all staged line changes et voilà, that's what I wanted to get.

Sidenote: I am using gitkraken and as a beginner with git I enjoy using the GUI but the merge part with the options "no-commit" and "no-fast-forwarding" had to be done via the git console (at least I could not find a way to to that using the GUI). Choosing which lines to stage and which to discard is then an easy task via the GUI.

AlbertRapp
  • 408
  • 2
  • 9