Git:仅在本地修改时合并冲突

时间:2016-05-09 04:13:00

标签: git bash shell github

我有一个工具,它为我的网站生成数据,准备适当的文件结构并将其放在我的git存储库(本地)中。 要提交此更改并将其推送到远程仓库,我编写了一个简单的shell脚本。

每当我手动运行脚本中的所有步骤时,它都可以正常工作。但无论何时,我使用此脚本运行代码,我都会遇到合并冲突。虽然更改仅在我的本地存储库中。

下面是我的脚本

#!/bin/bash
# Set Java Home as per needs
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_11
# open parent repository of blog
cd ~/personal/github/blog/blog-raw-contents/
# stash any changes
git stash
# open output (prepared site) which is another github repo
cd ~/personal/github/blog/blog-raw-contents/output/
# stash any changes in this repo as well
git stash
# go to my tool folder
cd ~/personal/github/blog/tools/sfoanalysis
# run the tool
java -jar sfoanalysis.jar "$@"
# go to raw contents github repository
cd ~/personal/github/blog/blog-raw-contents/
# the new files would be created in a folder with current date
CURR_DATE=$(date  '+%Y/%b/%d')
# add, commit and push to remote repo
git add content/projects/StackOverFlow/data/$CURR_DATE
git commit -m "commit for $CURR_DATE"
git push
# this is a tool which converts raw content to site and places output in proper directory
shammy -b
# open site repository
cd ~/personal/github/blog/blog-raw-contents/output
# Works fine till here!!- perfect
# added pull for safety when this was not working
git pull
# add files which will be changed after running above script
git add projects/StackOverFlow/data/$CURR_DATE
git add index.html 
git add version.json
# commit changes
git commit -m "commit for $CURR_DATE"
# did this for safety (although no one else is changing)
git pull --rebase
# unfortunately it throws a merge conflict and script breaks here
git push
git stash apply
cd ~/personal/github/blog/blog-raw-contents/
git stash apply
下面的

是控制台外出

处理文件 - >这是shammy -b命令的结果。问题出在这一行

之后的某个地方
X11 forwarding request failed on channel 0
Already up-to-date.
[gh-pages 1fe1380] commit for 2016/May/09
 2 files changed, 2 insertions(+), 2 deletions(-)
X11 forwarding request failed on channel 0
Current branch gh-pages is up to date.
X11 forwarding request failed on channel 0
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (10/10), 982 bytes | 0 bytes/s, done.
Total 10 (delta 6), reused 0 (delta 0)
To git@github.com:mohitkanwar/blog.git
   2bb455f..1fe1380  gh-pages -> gh-pages
Auto-merging version.json
CONFLICT (content): Merge conflict in version.json

请帮我确定问题。

1 个答案:

答案 0 :(得分:1)

我的第一个想法是你需要在字符串周围使用引号,否则许多命令会将空格解释为参数分隔符。我首先尝试引用传递给命令的大多数字符串。

您通常可以通过bash调试容量确认空白的情况。使用bash -x ./script.sh启动bash脚本,或添加脚本set -x以查看调试输出。