I imported an external project into my project by dragging its project file into mine. It didn't work. Now those files show up whenever I check something in. I don't want them and I never select them at checkin, but how do I get rid of them? I don't find them in the underlying file system, and I haven't found any controls that will get rid of them. They appear in the source control navigator under the changes tab as Local Changes.
As far as I understand, you have a project in the local area that you version control with git. You tried something new on the project after the last commit. But you want to cancel the changes and go back to when the last commit was made. In this case you can use the following commands:
# Undo changes made to tracked files
git reset HEAD --hard
# Delete untracked files
git clean -f
# Delete untracked files and directories
git clean -fd
If there is valuable data between the last commit and the current state, you will lose as a result of the above operations. To prevent this situation, you can choose the following way:
# Secure the difference between the last commit and the current state
git commit -m "recovery"
# Revert to two previous commits
git reset HEAD~2
References
How To Undo Last Git Commit
Reset all changes after last commit in git
Related
I was trying to add a repository to my xcode project, but instead of adding my project files to the repository, git removed my entire project. I think I can use 'git revert' option to revert the changes, but how do I know where to revert to?
Get the list of commits using
git log this will list out all the commits with its hash, to revert the commit use
git revert (part of the hash)
for example if the commit hash is adghgd356484fghfbht76, do
git revert adghgd3564
If you have not pushed your changes to remote, you can run git reset --hard which will undo all your local changes and you will loose those changes from the history as well
I have gotten myself into some hot water regarding source control.
I had just gotten a feature branch to work that another developer on my team had created and developed, which required adding some files. He then added some additional code to the project, and I wanted to revert to the version of the branch I had started with before I pulled his new code so that I wouldn't have to worry about merging these new files.
So, as per git's recommendation, I unstaged the changes I had made and used:
git checkout -- ScrollingTextLabels.xcodeproj/project.pbxproj
followed by:
git pull
I had assumed that the pull would replace the project.pbxproj file with the one from the origin, but instead git spat out a lot of lines beginning with "delete mode", most disconcertingly:
delete mode 100644 ScrollingTextLabels.xcodeproj/project.pbxproj
Every time I try to open the project on this branch, I now get the following error message from Xcode:
Project /Users/myname/Documents/Code/organization/product-ios/ScrollingTextLabels.xcodeproj cannot be opened because it is missing its project.pbxproj file.
I have been able to switch to other branches, which are still working fine, and must have their project.pbxproj file.
Also, I attempted to use git reset --hard to no avail. Should I force an overwrite (a la How do I force "git pull" to overwrite local files?)?
Should I delete the branch locally and pull from origin?
All I want is for the remote version of this branch, which is working well, to appear unchanged on my computer so that I can open it and continue working.
The message
delete mode 100644 ScrollingTextLabels.xcodeproj/project.pbxproj
during a merge (or pull) indicates that the file was deleted in the to-be-merged branch. It does not exist anymore in the other branch, your co-worker must have deleted that file.
Deleting a branch and pulling does normally not solve anything. You already have all changes from the remote (probably in origin/branch). Either checkout a new branch from that commit, or reset to it (potentially losing all your local changes!)
Use git log origin/branch or gitk to view the changes of the branch. You can also show the log for this single file only with git log origin/branch -- ScrollingTextLabels.xcodeproj/project.pbxproj. This should tell you, what happened to the file and whether it was deleted in the branch.
I have been having some trouble committing a file to GitHub. I can make it to git add, but soon as I try $ git commit -m 'my message' I get an error, not allowing me to complete the process of adding a file.
$ git add HelloWorld.md
$ git commit -m 'Hello world'
I get the following answer (deleted: README.md & .DS_Store are in red):
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
deleted: README.md
Untracked files:
.DS_Store
no changes added to commit
If you changed the file but there is still nothing to commit, maybe you didn't add the file to git. (or replaced it after adding).
Try adding the file before committing:
git add filename.ext
Or simply add the whole dir:
git add .
Apparently you did not change anything in the HelloWorld.md file (or it doesn't exist at all), so there is nothing to commit. If you just want to add an "empty" file, make sure to touch HelloWorld.md first, so the file is actually created. If it does exist, edit it (using vim HelloWorld.md for example) and make sure to save the changes in your editor when you're done.
Once you've done that and there are actual changes to the file, you should be able to commit it.
You have nothing to commit. More specifically:
README.md was a tracked file, but you deleted without using git rm README.md. Git detects that the file has been deleted, but you still have to stage that deletion if you want the latter to be effective in the next commit.
.DS_Store is an untracked file; as such, it cannot be part of the next commit. (By the way, you should ignore such files globally.)
git add HelloWorld.md has no effect: the file is being tracked by Git, but there is nothing to stage in there, because you simply haven't made any changes to it since the last commit.
How can I tell? If HelloWorld.md were a previously untracked file or if it were a tracked file which you changed since the last commit, git add HelloWorld.md would have successfully staged those changes; there would have been something to commit, and you would have been able to successfully commit.
Make some changes, stage them, and then you'll be able to commit. Finally,
Your branch is up-to-date with 'origin/master'
simply means
You haven't created any commits on master since you pushed to origin/master.
Nothing to be alarmed about.
I added the same file again and it worked. actually the whole dir: git add .
I renamed our iOS project (client finally chose a name) following instructions in the most upvoted answer here. I pushed my changes. Now, when my teammates pull, they cannot open the project because Xcode cannot find the .pbxproj file. They subsequently reset to their good local versions.
As usual when I royally f**k up I tried a hard reset to the last good commit, planning to force push the good commit up to the remote. While the reset was 'sucessful', it didn't change the newName.pbxproj back to oldName.pbxproj. So I could not open the project. Checking out my faulty commit didn't help things either. I am back at square one.
.pbxproj is NOT in our .gitignore:
*.DS_Store
*.xcodeproj/xcuserdata/*.xcuserdatad
*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
*/*.xcodeproj/xcuserdata/*.xcuserdatad
*/*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
The only thing I can think of now is to reclone the project from a specific remote commit. How can I do this? Other options? Why won't a renamed .pbxproj transfer over in a pull?
If you do a git log -5 it will show your last 5 commits. Determine the version before you named the file, and you can do a git reset --hard HEAD~<number> where <number> is how many commits you want to go back.
Alternatively, with your renamed proj file, you could try to blow away your remote with a git push origin :branchName then push your local changed branch up to the remote git push origin branchName
Then, have your other team members do a pull from the newly pushed remote.
I created a simple Xcode project to try something out and accidentally forgot to disable the Git repository option.
Now Xcode is cluttered with source control things. How can I get rid of this afterwards other than copying all files by hand into a new Xcode project and making all project changes again?
Not sure I understand your question, but if you just don't want the project to be a Git repository, you can simply delete the .git folder located in the project's root.
if you hasn't shared your commits with others yet, please use "git reset -mixed" or "git reset -hard" to set master to the last changes you want.
if you want to change index and working tree, use something like: git reset -hard HEAD^
if you want to change index only and keep your Xcode as uncommitted , use something like: git reset -mixed HEAD^
see man git reset