Mohit Kanwar
Mohit Kanwar

Reputation: 3050

Git : Merge Conflict when only local modified

I have a tool, which generates data for my site, prepares proper file structure and places it in my git repository (local). To Commit this change and push it in remote repo, I have written a simple shell script.

Whenever, I run all the steps in script manually, it works fine. But whenever, I run the code using this script, I get a merge conflict. Although the change is only in my local repository.

below is my script

#!/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

below is the console outout

Processing Files --> this is the result of shammy -b command. problem is somewhere after this line

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 [email protected]:mohitkanwar/blog.git
   2bb455f..1fe1380  gh-pages -> gh-pages
Auto-merging version.json
CONFLICT (content): Merge conflict in version.json

Please help me identifying the problem.

Upvotes: 0

Views: 87

Answers (1)

John Mark Mitchell
John Mark Mitchell

Reputation: 4822

My first thought is that you need to use quotes around strings, else many commands will interpret the white space as a argument delimeter. I would first try quoting most of the strings being passed to a command.

You can often confirm what is happening with whitespace via the bash debug capacity. Start your bash script with bash -x ./script.sh or add in your script set -x to see debug output.

Upvotes: 1

Related Questions