1

Sorry in advance if this question is too related to other git merge questions. I just have the feeling that I haven't understood git well up to now...

I developed something which I call my 'todo list app'. It's a shell script to print a todo-list, sort the rows, add new rows, delete rows etc. Pretty handy! The todo-list is a txt-file saved on the hard drive. Whenever I call the todo command, it pulls the newest version of the txt-file from my Github repo to the machine I'm working on, edits the local file, and pushs it to Github again. By that, I can use the 'app' on different machines while having always the most recent todo-list available.

# get newest todo-list version
git -C ~/GITHUB/ fetch #git -C enables to use the todo-list-app in every dir
git -C ~/GITHUB/ checkout origin/master -- todolist.txt

# add, remove, (or just print tasks) and write changes to file
shelltodolistfunction

# push changed file to Github again
git -C ~/GITHUB/ add ~/GITHUB/todo-list-app/inbox.txt
git -C ~/GITHUB/ commit -m "update inbox"
git -C ~/GITHUB/ push

Fetching, pulling, and pushing is kind of slow. Because of that, I would like to add another flag to the todo-list (for the sake of convenience, I haven't shown the getopts structure of the app here), so that it only 'updates' (i.e. does the git stuff) when called like e.g. todo -update -rmtask "ask stackoverflow" -addtask "bake a cake".

However, this could lead to the problem, that there is a newer version on Github, while I apply some changes to an older version locally. When calling todo -update, I would like the app to automatically merge these two files, save the merged file locally and also push it onto Github.

Github version:

write todolist app
ask stackoverflow
plan holidays ### <- this line would not be on the local version before an update

Local version:

write todolist app
### ask stackoverflow # <- this line has been deleted locally
bake a cake # <- this line has been newly added

New version:

write todolist app
plan holidays
bake a cake

Can this be done automatically and does it make sense?

hyhno01
  • 177
  • 8
  • 2
    Does this answer your question? [git merge, keep both](https://stackoverflow.com/questions/13263902/git-merge-keep-both) – grg Feb 13 '20 at 20:26
  • Concerning my toy example, I guess it would hold on to the line ```ask stackoverflow```, which is on the file on Github, but has been deleted locally. Am I right? – hyhno01 Feb 13 '20 at 20:30
  • Good point, I guess working out what happened is going to require more than just looking at the diff – grg Feb 13 '20 at 20:48
  • This brings me to another idea. Finished tasks are written to a history file. I could first just look at the diff and after that delete all rows that are also in the history. However, I let the thread open, maybe there is a more elegant way – hyhno01 Feb 13 '20 at 20:54
  • 1
    Side note: in your question you talk about "pushing the file". Git does not push *files;* Git pushes *commits* (which of course *contain* files, but the important thing is, you get a whole commit, or not—you only get a single file if that commit's snapshot consists entirely of that one file). – torek Feb 13 '20 at 21:39

0 Answers0