Xcode 9.2 - Version control - how to revert back to earlier committed version - xcode

Im using Xcode 9.2 with bitbucket for version control. I have the past 4-5 hours worked in the master branch. I realise now that I want to keep the work that I have done today but not part of the master branch but rather as a new branch.
I have been able to push the existing version to the new branch, but it required me to commit to master first (locally).
Now I want to revert the master back to the version from yesterday, and commit this at the master. This is where the problem occur. I am able to revert back to the previous committed version by checkout the commit - but then I am not on the master branch anymore, and I can't commit to master or push to master.
How can I revert back to the master to a previous build, and basically remove the changes done the past 4-5 hours?

For the next time you realise before you commit:
Open up terminal
cd ${path to your project}
run git stash command
When you stash the not commited changes, now you should be safe to switch and make new branch
now change to the new branch and apply stash: git stash apply
Enjoy your changes.
Since I am confused as hell and this happens to me from time to time, I created alias in my .bash_profile file to delete the local commits by simply making one command in terminal:
alias fixFuckup="git reset HEAD~1"
simply run the command and you will be reset to the state before the commits. Actually this resets one commit.
git reset HEAD~1
to reset to the state before doing lot of commits, prefer using this.
git reset --hard HEAD^
for clarifying the changes please take further look at this:
what is difference between 'git reset --hard HEAD~1' and 'git reset --soft HEAD~1'?

Related

How do I undo the most recent commits in Git?

I am not able to undo the commits in git. It shows technical errors while doing so.
I have tried to navigate to the folder for my git repo and expecting to solve the problem at the earliest.
This post has explained undoing commits previously, presuming the issue is sourced in your local repository.
Link: How do I undo the most recent local commits in Git?
command:
git revert HEAD
you can mention the commit ID to revert the commit, if mentioned HEAD it will revert the last commit

how do I restore to a previous version wherein the .env file is available [duplicate]

This question already has answers here:
How do I reset or revert a file to a specific revision?
(35 answers)
Closed 3 years ago.
Just a dumb question from just a newb in git, Messed up alot with git, but now I was wondering if how can I restore to a previous version in the application, since my .env environment configuration file is now gone in my current master branch, I did merge my other branch with this one. I knew I made my latest work on my chat-feature branch, pretty much the 100% of the application was there, since the chat part and the payment feature of the application was there but when I checkout there, its not even working, I was wondering how can I go back to that previous commit that I made. When I git log I want to be back to this specific version.
Restore + push --force
I don't like to recommend anything that requires --force but in your case it may be the cleanest solution. If you shared your code with others, don't follow this - you're changing history.
Let's make master be like chat-feature.
Make a copy of the repo (on your drive), just in case.
git checkout master
git checkout -b master_copy (optional, but let's store what we currently have in master as a new branch; this will make it easy to use it if rewind too much)
git checkout chat-feature
Check that this is what you want master to look like.
git log -n 1
Copy the commit id
git checkout master
git reset --hard <commit-id>
Double check that things work and that's what you want.
git push --force

Why doesn't Git track files modified in Xcode?

I'm using Git on the terminal to commit changes & push them to a remote repo.
Git can recognize when I create a file or modify a file via VS Code. However, when I work on my files on Xcode and save them, Git doesn't track any changes. It tells me:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
What's the problem and how can I fix it?

Merge conflict while trying to merge stashed code

So I stashed my changes for my Swift project so that I could make a pull request and then merge the changes I made with the new pull. However, whenever I try to merge my changes I get a merge conflict, regarding the UserInterfaceState.xcuserstate XCode file. Nothing I'm trying is allowing me to merge my stashed code, and I'm worried that I'm going to lose an afternoon's worth of code.
I tried adding *.xcuserstate to .gitignore, but that didn't seem to do anything. I then tried deleting the file, which created a modify/delete conflict from the version in the stash. Here's the error I'm getting when I try to get the stashed code:
$ git stash apply
CONFLICT (modify/delete): myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate left in tree.
Trying what Flows recommended this was the output I received:
$ git reset --hard
HEAD is now at e509ffa Fixed bugs
$ git stash pop
myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate: needs merge
unable to refresh index
$ git rm myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate
myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate: needs merge
rm 'myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate'
$ git stash pop
CONFLICT (modify/delete): myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of myProj.xcodeproj/myProj.xcworkspace/xcuserdata/lnd.xcuserdatad/UserInterfaceState.xcuserstate left in tree.
Is there anything that I can do to fix this? Nothing seems to be working, so any help would be greatly appreciated, thanks.
You can try this
Reset master with --hard option to origin/master
Apply the stash with stash pop
Git should tell you there is a conflict. Edit UserInterfaceState.xcuserstate file to see the conflict and correct it.
git commit
If it doesn't work, could you paste all git output of the commands ?

Git branch not working for me in Xcode

I am working off a github branch, call it "main12"
I then do a git checkout -b newFeature.
I do some work on newFeature
I then need to go back to main12 to do some work
I close down Xcode.
I switch to main12 via terminal git checkout main12
Open xcode and verify xcode is on the main12 branch.
All my changes made in newFeature are now in my main12 branch
What gives? Did I miss a step? Why wouldn't my code in main12 be the way I left it?
Did you commit or stash the changes made to newFeature? If not, probably the command git checkout main12 have failed. Closely watch the command line output of that command and verify.
Any changes you make to the current branch should be committed or stashed(discard temporarily, store it back whenever you need) before checking out another branch.
Try the following command before you checkout main12
git commit -am "some commit message here"
It is likely the case that you forgot to commit your code before checkout to main12 branch. Currently, you should have uncommitted code (marked in Xcode as M/A besides the file name). You can switch back to newFeature branch, commit the code, and switch back to main12 branch.

Resources