git - git如何自动合并?
问题描述
如果这个问题与其他问题过于相关,请提前道歉git merge
。我只是觉得到目前为止我还没有很好地理解git......
我开发了一些我称之为“待办事项列表应用程序”的东西。这是一个用于打印待办事项列表、对行进行排序、添加新行、删除行等的 shell 脚本。非常方便!待办事项列表是保存在硬盘上的 txt 文件。每当我调用 todo 命令时,它都会将最新版本的 txt 文件从我的 Github 存储库拉到我正在处理的机器上,编辑本地文件,然后再次将其推送到 Github。这样,我可以在不同的机器上使用“应用程序”,同时始终拥有最新的待办事项列表。
# 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
取、拉和推有点慢。正因为如此,我想在 todo-list 中添加另一个标志(为了方便起见,我没有在这里显示应用程序的 getopts 结构),以便它只“更新”(即 git 的东西) 当被称为例如todo -update -rmtask "ask stackoverflow" -addtask "bake a cake"
。
但是,这可能会导致问题,即 Github 上有更新的版本,而我在本地对旧版本应用了一些更改。调用todo -update
的时候,我想让app自动合并这两个文件,把合并后的文件保存到本地,同时推送到Github上。
Github 版本:
write todolist app
ask stackoverflow
plan holidays ### <- this line would not be on the local version before an update
本地版本:
write todolist app
### ask stackoverflow # <- this line has been deleted locally
bake a cake # <- this line has been newly added
新版本:
write todolist app
plan holidays
bake a cake
这可以自动完成吗?有意义吗?
解决方案
推荐阅读
- python - 如何在我的海龟程序中添加倒数计时器?
- sql-server - PySpark:使用内连接、Case 语句和 Where 语句翻译 MSSQL 代码
- python - Python数字暴力破解
- node.js - NodeJS 服务器写入响应并开始文件下载
- java - Hystrix 请求缓存和并行流
- python - HTTP 代理以即时修改传出的 HTTP 请求
- javascript - 使用 react-router-dom 链接到特定的 mui-tab
- r - 在R中压缩字符串
- c# - C# 单元测试 - 实际:(null) 使用 xUnit 中的 List 和 Moq 框架的结果
- ajax - 从具有动态 ID 的按钮获取 ID