簡體   English   中英

Git:僅本地修改時合並沖突

[英]Git : Merge Conflict when only local modified

我有一個工具,可以為我的網站生成數據,准備適當的文件結構,並將其放置在我的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

請幫助我確定問題所在。

我首先想到的是,您需要在字符串周圍使用引號,否則許多命令會將空白解釋為參數定界符。 我首先嘗試引用大多數傳遞給命令的字符串。

您通常可以通過bash調試功能來確認空白的情況。 使用bash -x ./script.sh啟動bash腳本,或者添加腳本set -x以查看調試輸出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM