Xcode, remove files from a branch so they don't have to be merged? - xcode

I've accidentally commited my cocoapods project from my workspace into a branch.
Now that I need to merge the branch back to the master branch, I can't proceed.
I've been through all all of the files and accepted the changes in each files (which took quite a long time), however the merge aborted, with a message saying it couldn't overwrite local files.
I'd like to remove cocoapods and not have changes under git. However, I'm not sure how to proceed. I've seen that you can remove find at the command line, but I'm concerned as I'm in a branch.
Help!

What you need is probably the filter-branch feature of Git to remove some files from every commits: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#The-Nuclear-Option:-filter-branch
Try something like below on your branch:
git filter-branch --tree-filter 'rm -rf <yourCocoapods>' HEAD

In the end I physically deleted my pods folder, then committed the deleted files. I was then able to merge :)

Related

git pull added tons of untracked files and modified files

I am not very familiar with git as I just use it in the most basic manner. Lately I've been running into this strange behavior which makes no sense to me and causes a huge disturbance in my productivity. For certain branches when I run git pull instead of just getting the latest commits from the remote repository like I expect, I get an ENORMOUS list of modified/deleted/added files as well as an enormous list of untracked files. The branch I am pulling from is our team's master branch. I am just trying to keep my local copy of master in sync. What are these other untracked files showing up as well as these modified files? I didn't touch any of these other files.
What makes the problem worse is that I can't delete these untracked files or anything. I've tried `git clean -fx' and it only removes 3-4 files but still leaves hundreds. At this point I just want to get rid of all of these files, delete the branch, and pull the branch from remote again.
I tried doing the following:
git fetch --all
git reset --hard origin/<remote_branch_name>
but I received an error because Git couldn't create a symbolic link. I am using Git on Windows.
Why is git pull doing this, and what should I do?
EDIT: I was finally able to run the git reset command when I ran my prompt as an admin, but it still doesn't explain this weird git pull behavior.
It seems to me that the 'git pull' action did not complete successfully.
It is possible that you modified some of the files as an admin, and when pulling as non-admin user git tries to modify or delete a file and has no permissions to it.
Therefore you stay in some half baked state.
What do you see when you run git status?
Is there any error in the git pull?

Git giving warning: unable to rmdir

I am using git bash on windows 10 which was recently updated to creators update.
whenever i am trying to switch between branches i get following thing
$ git fetch && git checkout master
warning: unable to rmdir Ionic_Developemnt: Directory not empty
Checking out files: 100% (6312/6312), done.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
I don't know why this is happening also there is a .git hidden folder in the Ionic_Development folder
Can anyone help with this why so error _/_
warning: unable to rmdir on git checkout means that you're switching to a branch where this directory doesn't exist; git tries to remove it but there are some temporary files that git cannot remove; the directory is not empty so git cannot remove it also, hence the warning.
This happens mostly when your files are still in use. I personally experienced this sometimes with atom editor. Try to close your editor, and maybe any running compilers that are watching for changes too, and try to checkout again.
Found the answer, instead of git checkout, use git checkout --recurse-submodules.
Use git config submodule.recurse true to tell git always use --recurse-submodules (only in git versions 2.14+), add --local if you want that only in local project level.
Reason:
This issue happens on (Git < 2.13) when git checkout could not take care of those submodules correctly.
Reference: https://github.com/gitextensions/gitextensions/issues/2966#issuecomment-622666568
Original Answer
Actually I think this answer is partially right :O
If a folder is tracked by local .git within that folder, it would be changed according to .git when you switch branches (e.g. deleted from our point of view, if the other branch does not have this folder).
If a folder is ignored by .gitignore, the folder would be left unchanged when you switch branches.
However, if the folder is a submodule, which is tracked by submodule .git, local .git would try use rmdir when switching branches, which caused the problem.
I know this is old, but in case anyone stumbles on this, as I did, it can also be that you're switching to a different branch and you have a Git submodule. Look for the .git hidden folder in the directory, you can delete it if you don't need it to be a submodule--just be sure to commit the folder to the parent repo in the current branch before switching.
rm -r .git

Issues with git branch checkout due to untracked working tree files

I thought I put the days of Xcode + git issues behind me. Guess not. I am getting this git error when trying to checkout another branch.
error: The following untracked working tree files would be overwritten by checkout:
RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme
RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist
Please move or remove them before you can switch branches.
Aborting
Very well I say, let me remove these files:
andrewjl$ git rm --cached RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate
fatal: pathspec 'RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate' did not match any files
At this point I'm not sure what to do. These files are all listed in my .gitignore and I also gave git clean -f -d a try as well. No dice. Anyone know what's going on here?
The files are untracked: git rm --cached cannot find them because there are not in the index. Just delete them, using your file manager or rm. Then checkout should work as expected. Note that git status will show you what git sees the files as (tracked, changed, untracked; with an additional option it will also display ignored files).
they arent in git but there locally .. that means when you switch those would be lost and git doesnt allow that
remove them locally:
rm RCAlpha.xcodeproj/project.xcworkspace/xcuserdata/andrewjl.xcuserdatad/UserInterfaceState.xcuserstate RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/RCAlpha.xcscheme RCAlpha.xcodeproj/xcuserdata/andrewjl.xcuserdatad/xcschemes/xcschememanagement.plist
they are recreated by xcode anyway. nothing important in there!
Try this
git rm --cache */xcschemes/xcschememanagement.plist
git commit -m "Good bye xcschememanagement.plist"
Git stash and git checkout "yourBranch"
git clean -f
solve the problem for me, they are untracked files when run clean they get remove.

Using Xcode 4, can I get rid of a git repository but keep my whole project in its current state?

I started using a git repository in Xcode 4 without previously knowing git and it looks like I've messed up the state of the repository. I first made a repository, made many commits on it, then made a branch and made many commits on the branch. Then I tried to merge the branch back to the master branch using the Xcode organizer but it won't let me switch to the master branch. When I try to switch to the master branch I get the error: "you need to resolve your current index first". I don't know what that means exactly. I did a commit and everything is up-to-date. I don't see anything in Xcode menus or screens that mentions "index". After reading some postings about git and playing with the git command line I'm clearly lost and have no clue what to do.
I know the right thing to do is learn git and learn how to use the command line tool, but I don't want to take the time for that now. I don't really need the repository functions anyway, I was only using them to see what they were like. I could keep copies of the whole directory and/or I could use snapshots to give me a way to go back to an earlier state.
The current state of the code on the branch I've been working on is fine, so what I'd like to do it un-git it. IOW eliminate the repository altogether but keep the project in its current state. Is there a way to do that? I don't need to go back to the project state on the master branch, I only need the current state.
The quick way to un-git a project is open Terminal, go to the project directory, and remove the .git directory
cd ~/Documents/MyProject/
rm -rf .git
Be careful with the rm command, you only want to nuke the .git directory. Not your code.
I don't know how to make the .git directory visible in finder.
To remove all traces of git delete the .git folder in your main project folder. Also look for any .git* files (eg. .gitignore, .gitmodules). If you have submodules you will need to check your subfolders for these files and the .git directory as well.
On linux, this will do it:
find /base/dir -name '.git*' -prune -exec rm -rf {} \;

Github. How do I make changes to what is ignored via .gitignore?

I have an Xcode project that uses git for version control. I have a .gitignore file to ignore the build subdirectory:
build/*
I recently added a subdirectory that contains an Xcode project and forgot to update the .gitignore file before checking it in.
Is there any way to make git ignore the build subdirctory now, after the fact?
Thanks,
Doug
git rm --cached dirToignore
echo dirToignore >>.gitignore
From there, a new commit will record that:
dirToignore is no longer par of versioned data
dirToIgnore won't show up anymore in git status
See this SO question for similar advices.
If you want to amend previous commit in order to remove said subdirectory from an old commit, see this SO question:
git commit --amend
can help you remove it from at least the last commit.

Resources