Git merge conflict with workspace.xml - ruby-on-rails

I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?

.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull

git commit -am "message" worked (as opposed to amending a commit)

I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.

Related

how do you move folders into the bitbucket repository without removing other folder?

Suppose that you have a repository in bitbucket and you need to create a new folder inside the bitbucket repository and move your files there.
The way that I am moving it removes history, all the previously saved files in the repository and replaces the new one.
I found some similar questions here but they are old and they did not work out for me.
Please advise!
Edited: the wat that I am doing :
git init
git add .
git commit -m "my new commit"
git remote add origin https://.....
git push -f origin master
This removes any other code.
Git tracks exactly what matters, namely "collections of files".
git mv oldname newname is pretty much like mv oldname newname; git add newname; git rm oldname
It mostly depends on your client I think to track renaming of files. Sometimes it works, but if the content is changed drastically then it considers it as a new file.
An other question on here that discusses this issue.
What's the purpose of git-mv?
Update:
https://git.wiki.kernel.org/index.php/GitFaq#Why_does_Git_not_.22track.22_renames.3F
As a very special case, 'git log' version 1.5.3 and later has '--follow' option that allows you to follow renames when given a single path.
Mail by Linus on this topic.
Git has a rename command git mv, but that is just for convenience. The
effect is indistinguishable from removing the file and adding another
with different name and the same content.

How do I pull your last commit from GitHub to C9?

So, I kind of messed up and went and deleted all my files on C9. I haven't saved anything yet, so I'd like to pull my last commit into my C9. I read somethings that said I should download the zip file of the commit, but I don't really know what to do with that. If anyone could help me I would really appreciate it!
If you guys need any more info, I want to pull from my last commit because I deleted all my branches except my master branch and all the hidden files that I might need later. I couldn't really find anything about pulling into C9 from Github so I thought this would be a good question to ask you guys.
you can delete all the files that you do not need then run the following
cd ~/workspace # make sure you are in the right folder
git init . # create new git repo instead of the one you've deleted
# now add your github repository as origin
git remote add origin git#github.com:jinntakk/upskill_saas_tutorial.git -f
git remote set-head origin -a
git fetch # fetch your commits from github
git reset origin/HEAD --hard # reset working tree to the remote

problems with pulling or pushing the code

My question is very basic but still it is unclear for me. I am working on a rails project with multiple developers. All of them can pull or push the project. So let me explain my scenario. If I am making changes in my code for the first time and the other developers are also making changes, when I try to push the project I am able to do so. But the other developer face problem in pulling the project. After that If they are able to make changes and pull the project then I am unable to push the project or pull the project. This is how we push the project first:
git add .
git commit .
git pull origin master
but the error comes warning: Cannot merge binary files or I get the error git pull fails with “Untracked working tree file 'blah' would be overwritten by merge
The problem is coming because you and your friend doing changes on the same line of the file and git is unable to decide which one to take. So in this case its better to go for stash first to save your code.
The code will be:-
git stash :- To save your code
git pull :- To pull the code from git
git stash apply :- To merge your changes with the pulled files, if any merging error is coming then it will hit an error saying merge-conflict,you have to resolve that manually.
git add :- To add the files
git commit -m "Commit message" :- To commit it
git push :- To push to the repo.
I think this will solve your problem
git checkout accepts --ours or --theirs options for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:
$ git checkout --theirs -- path/to/conflicted-file.txt
to use that version of the file. Likewise, if you know you want your version (not the one being merged in) you can use
$ git checkout --ours -- path/to/conflicted-file.txt
ref:Resolving a Git conflict with binary files
In your case the file is 'blah' in the working directory of remote location. so u can keep one of them.

Unable to commit to git repo. Pathspec 'origin' did not match any file(s) known to git

I'm working off of an existing project that I have been committing and pushing to git. For a couple reasons, I had to change rails versions from 4.0 to 3.2.6 and use existing project files from a tutorial by downloading the files and replacing my local app folder with them.
Now I can't push to my existing repo on git that I have been working on.
If I try to commit, I get two errors:
error: pathspec 'origin' did not match any file(s) known to git.
error: pathspec 'master' did not match any file(s) known to git.
I tried to delete the local app folder, clone the repo and then replace all of the files with the 3.2.6 version app that I have been working on but I still get the same commit errors.
You can try to specify the full git push command:
git pull -u origin master
If it doesn't work, check if your remote declaration were altered in any way:
git remote -v
also, as show in this article, list references and branches:
git branch -avvv
git show-ref
check that you are in a branch, and not in a detached HEAD.
Make sure you don't have a branch named 'origin' (which would be confusing here)
As mentioned in this issue (for git svn, which isn't your case, but can still give interesting idea), trying to clone again the repo could lead to a non-corrupted .git folder, and the ability to push again.
Did you checked your git config file placed in
.git/config
in your project folder? You can find the details of your repo & branches information in this file.
Hope it helps.

Starting over with Git

I decided to learn how to use Version Control over Christmas break, so I downloaded Git, opened a GitHub account and started reading the online tutorial linked to from the GitHub website. When I got to this part http://progit.org/book/ch2-2.html I got stuck because I wasn't sure how to add files. For instance, I tried
git add C:/Finish.txt
And it said
Fatal: 'C:/Finish.txt' is outside repository
I was confused until I remember that a long time ago I had tried teaching myself Ruby on Rails and played around with Git back then. It never really went anywhere, but there's all this residual stuff floating around my system and I don't know how to change it. For instance, my Untracked files (which should be empty) are rails_projects/ and sample/.
How can I just erase all the old stuff and start over?
You should make a folder for your repository, move Finish.txt to that repository, then do git add.
For example:
# here you create C:\myrepo
cd C:\myrepo
git init .
# here you edit C:\myrepo\Finish.txt
git add Finish.txt
git commit -m "Added Finish.txt"
Start a new repository, e.g.
c:
md c:\newrepo
cd c:\newrepo
git init .
copy \Finish.txt .
git add Finish.txt
git commit -m "started over"
I strongly recommend against adding anything to C:\, let alone putting a git repo there. Unless of course you want to accidentally add all of your system disk to git :)
I can also heartily recommend using TortoiseGit which has some excellent explorer integration.
Delete any .git folder that you find in your drive.
To create a repo go to a folder that you want the repo in ( and not just randomly), do:
git init
Then proceed... Add only files that you put within this repo and not randomly from some location.
It would be very unusual to have the root directory of your hard drive be a git repository. That's probably why it's giving you the error.
git repositories are typically in a subdirectory and that subdirectory is typically a project.
To initialize a subdirectory as a git repository, you'd do:
git init (directory)
Then you'd add your files and commit.

Resources