Cannot change/delete/commit/discard current branch - xcode

I created a local branch from a git repository that I am working on. I have done this many times but for some reason the branch was created and put a bunch of random junk all over my code. (like random text and arrows).
So I decided to wipe the branch and attempt to recreate it since I have never seen this before. I went to switch branches and it would not let me because "Working copy is modified." I attempted to commit changes but it said there were none to commit.
I then went on the terminal and tried to commit, discard, delete the branch, change branches. All of these went unnoticed (either 'nothing to commit/discard' or 'cannot delete/change unmodified current branch').
I am now stuck, not being able to change branches, commit the "changes", discard changes, or remove the branch. Any thoughts?

Do the following:
git reset --hard HEAD
git checkout master
git branch -D <branch you want to delete>
This will reset all the changes you currently have. And then will checkout the master branch to continue working on. And finally delete the branch you want to remove.

Related

xcode9 "The current branch could not be determined"

pushing to github was working fine. I think this problem started when i checked out a branch from github. How do i fix this? When i try to push to github now, i get the error "The current branch could not be determined."
Also, all my local commits do not show up with comments in either of my local branches. at least not in xcode 9 UI. I don't really know how to use the local git to check these things, so if someone wants to point me to documentation that would be helpful too.
I had this issue, you need to get down and dirty in Terminal :)
The issue is most likely a detached HEAD
This recovery is based on you have made changes whilst head detached and you want to keep these changes.
Navigate to your project directory and execute: git status
If you have a HEAD detached message then:
Commit changes: git commit -a -m "you commit comment here"
Create a local temp branch: git branch temp
Check out the previous branch (the branch you want to use i.e. master): git checkout master
now merge your recent changes (from the temp branch): git merge temp
Your all done, go back into Xcode and your back on your branch and everything as you left it :)
Hope this helps.
Type these commands (1-4) sequentially in your Command Prompt :
git commit -a -m "you commit message here"
git branch temporary
git checkout master
git merge temporary
Now head over to source control navigator pane in your Xcode project and delete the "temporary" branch from Branches Tab
Source Control navigator pane image
I had the same issue after checking out a previous commit and have found a fix.
In Xcode go to Source Control > Clone > Clone the repository you are trying to push and save it, then delete your old Xcode project and replace it with the cloned project and it should work as normal.

Can't commit because someone else pushed, can't pull without discarding my changes in git

I am working with a friend on an iOS project, and we are using git for versioning, with Xcode. My friend has committed the changes, and I have my changes locally. When I try to commit my changes, I'm getting this error in Xcode:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
When I try to pull, Xcode warns me about losing my local changes:
How can we simply merge the changes? I've used TFS before, and things were more much easy, we've checked in changes, and got latest, and if there was any conflict we could solve it. We don't need branching etc, we just need to keep our code in sync.
How can I solve this "deadlock" simply as possible? Or in other words, what is analogous to "just checking in/merging/getting latest in TFS" in git? Xcode built-in solutions preferred, without terminal.
UPDATE:
Here is what I get if I type git status at the terminal.
Cans-MacBook-Pro:myappname Can$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: BigPostView.xib
modified: BigPostViewController.h
... (many others displayed here)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: myappname/Storyboard.storyboard
Cans-MacBook-Pro:myappname Can$
You should always be able to commit your changes, since that's a local operation. You'll get an error only when you try to push your commited changes.
In order to push your commit, you'll have to pull your friend's changes first.

GitBucket: error: Your local changes to the following files would be overwritten by merge

I have searched everywhere and tried various solutions but am still getting the error:
Your local changes to the following files would be overwritten by merge
i have nothing to commit as status tells me the following:
# On branch develop
# Your branch is behind 'origin/develop' by 1 commit, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
nothing to commit, working directory clean
So then I do a git pull, then get the following:
Updating 67020e6..6dd23de
error: Your local changes to the following files would be overwritten by merge:
app/filename.php
Please, commit your changes or stash them before you can merge.
Aborting
But as I have nothing to commit and if I do a git stash I get No local changes to save
So how can I fix the problem and download and update my local machine with my remote amends.
Bit of history incase:
I have to local machines one at home and work I have done the amends at home and pushed them and I am now trying to update my local work machine with these updates.
EDIT UPDATE
As I cannot answer my own question for a while I found what for me solved this answer:
on the branch I wrote:
git reset --hard
Then the pull worked.
While looking around i tried the following that seemed to fix my issue at the time.
While on the branch i wrote.
git reset --hard
Had you ever previously done git update-index --assume-unchanged <file>? That could be a potential reason for your situation.
To fix, you do git update-index --no-assume-unchanged <file>. Then you should be able to stash your changes and continue with the merge.
Faced exactly the same problem. I was used to CVS before I started exploring git. I think running git pull --rebase origin master is the way to go for the kind of workflow that you and I use.
Refer to https://www.atlassian.com/git/workflows#!workflow-centralized for a more detailed explanation. I definitely know the answer is somewhere in that article, but I didn't understand the article completely.

Github failed push

So to make a long story short, I've been working on a web app for the past few months. Recently I had to get a new laptop and cloned the repository from github onto my new machine... However whenever I commit changes to my app and attempt to use git push -u in the app's root directory i get the following message:
To git#github.com:acc/etc.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:acc/etc.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
but when I try git pull git#github.com:acc/etc.git master I get a message telling me that the pull was aborted.
From github.com:acc/etc
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
config/routes.rb
test/fixtures/users.yml
Please, commit your changes or stash them before you can merge.
Aborting
so then i commit my changes using git commit -m 'fixing' and then attempt git pull again.
however this time I got messages stating that practically all my files had an "Auto-Merging CONFLICT"
am i totally screwed with this particular repository? I'm not really sure what to do since git is still somewhat new to me....
am i totally screwed with this particular repository?
No, but you will have to do a manual merge, since Git can't figure it out. git status will tell you which files need editing. The files themselves contain markers indicating where you should edit. When that's done, git push should work again.
If the changes aren't that big, consider making a copy of the entire folder/project in a different directory outside of the project, then git reset --hard HEAD will wipe out, erase and delete your recent changes.
You can then apply them again individually using your save3d copies for refernce.
Make sure sure you git add before git commit of course.
Finally if you get auto commit merge issues you can always just edit the files manually to resolve.

Git - Switching branches (windows) & uncommitted changes

I'm having a hard time understanding some git/DCVS concepts. Here's what happened:
I created a git project, and imported it from an SVN repo
I made some commits
I wanted to experiment something, so I created a branch called constants-update
I switched to constants-updatebranch, moved some files, deleted others and added many more
I committed to this branch
Now I'm trying to switch to my master branch using git checkout master
I got this error: error: You have local changes to 'src/groovy/Constants.groovy'; cannot switch branches.
My understanding of DCVS is that I can switch branches at will, even if some branch has more or less files than the others, as long as I commit my files. I've tried committing with git commit -a and switching to master branch, but I have the same error.
As a side note, when I commit git warns me that LF will be replaced by CRLF and warns me about some trailing whitespaces also; after I commit I do a git status and a bunch of files always appear as #modified ....
Is this related to git/windows, or I do not understand correctly what it is supposed to happen? I just want to switch to my master branch without losing my changes in the other branch.
Lookup git-stash for changing branches while there are unsaved changes in the current branch.
You are correct in your thinking about how this should work.
However, it sounds like git is having issues with the line endings, and it thinks all your files are modified even when they aren't. I don't use git on Windows, but I was going to suggest the "core.autocrlf" option to make the crlf handling work. However, the following blog entry indicates that this might not be a good idea: http://weierophinney.net/matthew/archives/191-git-svn-Tip-dont-use-core.autocrlf.html
I solved the problem hacking my pre-commit hook (commenting these lines in .git/hooks/pre-commit with a #):
# if (/\s$/) {
# bad_line("trailing whitespace", $_);
# }
Just use the following option in .gitconfig file which resides in your users directory.
[core]
autocrlf = true
And it will solve the issue.

Resources