Reverting to a previous version git repo - xcode

Hello so I've done this before I just completely forgot how.
What I am trying to do is I have a remote on my github repo and I have an old version that I would like to revert to meaning I can commit from it and it would now be at the top of the repo if that makes sense since my current repo is having some issues and I want to go back to a specific version.
I remeber slightly what I was able to find out last time which worked out beautfully and that was I checked out the version I want and then I created a new remote or split the remote or something, added the version on to the new one and then merged the branches or remotes. It was something along those lines, I just don't remember exaclty and I would appreciate someone guiding me through as I am unable to find the old posts I was previously looking at.
This is a Swift Xcode project
Thank you in advance for all of the help

Instead of rebasing/restting your branch, you could revert the past commits you don't want, in order to create a new commit which would restore the state of the branch to the content of an older commit.
See "Git reset --hard and a remote repository"
git revert HEAD~N
git push

Using terminal git, you can do git rebase -i HEAD~N where N is the number of commits you want to backtrack. Then you can choose to drop or edit commits. In your case, you only need to drop the most recent commits and then you will be effectively back to one of your previous commits. In other cases, this can be used to combine/split commits as well.

Related

Can tortoisegit be configured to automatically merge and it that fails to produce a conflict file to use for merge

We have been using tortoise svn for quite a while and loved it.
When we did an update it would automatically merge and if there were conflicts
it would produce a conflict file and I could use the merge tool on it.
With tortoisegit, if someone has been in the file it does not even attempt to
merge just produces message similar to "Cant". Is this a problem with git or
tortoisegit. We used tortoisegit because of how easy tortoise svn was to use and did not get in the way. Whereas with tortoise git we get the "CANT" and many dialogs to
click on when we do anything.
How can I merge in tortoisegit if there is a conflict, and is there someway to tell
it to produce conflict files.
I will try to summarize how Git synchronization with remote repository works.
You Commit your changes into a local branch.
You want to Push your changes into remote repository. If Git finds out there are new changes in remote tracking branch, it will not allow the Push and will say "you have to do Pull first". (This is a restriction in the Git itself, not only in TortoiseGit.)
As per instructions you do Pull. New merge commit combining yours and others' changes has to be created. If there is no conflict, merge commit is created automatically. If there is a conflict, TortoiseGit force you to resolve it and Commit changes manually.
Finally, you do Push.
I think the main difference from SVN schema is the creation of merge commit, but I don't see this as a disadvantage at all.
A good way to avoid merge commits is to always do Pull before committing so you commit to the newest version of the branch. However if you have working tree changes in a file which needs to be updated during Pull, Git will say Your local changes to the following files would be overwritten by merge and Please commit your changes or stash them before you merge. In this case you should do Stash changes, repeat Pull and finally do Stash Pop.
You may call all these operations from TortoiseGit context menu or you may try to use Git Sync dialog.

Xcode's commits are outside braches. How to return to branch and not lose new code?

I have small experience using git repos. So i'm a little bit confusing, trying solve my problem.
I use Xcode installed (not vie terminal) git system and remote github repo.
The problem is for some reasons I've been commiting code for last 2 weeks not inside my master branch (it's the only one), but somewhere else (in source control navigator it seems on project level (high blue folder with project name)). So because of that i coudn't and still cant push changes to github.
if i select master branch, the last commit was 2 weeks ago. However if i select highest blue folder with project name, i see fresh commits.
How can i carry over all commits (or at least the last one) back in my master branch, which is connected with remote github repo and not lose data?
And what actually happened?
From your comments, it appears that somehow you ended up in a detached HEAD state, to which you have made several commits. However, it is easy to get out of this situation. Just checkout a new branch from your detached HEAD state, and then merge this branch back to master:
# from ac4c47c
git checkout -b your_branch
git checkout master
git merge your_branch
Then, you may push master to GitHub. Or, you could push your_branch to GitHub and open a pull request back to the master branch. Note that if you have unfinished work currently in your working directory and/or stage, you should finish it and then commit before creating your_branch.

Why commit updates are shown in main folder and not in master branch? Xcode

I just did two commits and they don't show up on master branch, they do in the main project folder, same in Bitbucket repo, it only shows yesterdays commits. I'm not sure how to fix this. If I try to check out to master branch, I get a warning to lighter push or discard changes, but if I push them, they don't appear anywere. I'd appreciate very much a little explanation on how that could have occurred. I'm just starting with version control and I surely messed it up when I checked out on previous commits to check some part of the code, although I thought I did check-out again on last commit.
Many thanks as usual.
I solved it as so:
Selected the latest commit on actual Master branch.
Created a new branch from it and named it anything but Master. That is an exact copy of actual non synchronised Master branch.
Deleted actual Master branch.
Created a new branch from latest commit on newer created branch at point 2 and named it Master.
Deleted branch created at step 2.
Pushed the missing commits to Bitbucket.
Now I have a new Master branch that is in sync with its bucket.
Hope this will help others.

I deleted a branch locally but it keeps coming back (autocomplete issue) [duplicate]

I used git branch -d myBranch to delete a branch. However, when I am on master and try to checkout a new branch with git checkout, myBranch still appears in the tab-autocomplete.
How do I remove the name myBranch from tab-autocomplete for git checkout?
git fetch --prune --all
Posting this as its own answer since it's a one-line fix, but if you vote be sure to vote for twalberg's answer.
twalberg's suggestion to git branch -a led me on the right track; my coworker suggested git fetch --prune --all to prune all the dead branches from all the remotes, which is useful when working with lots of devs with lots of forks.
One possible reason for this is that, if a remote branch (e.g. origin/myBranch) still exists, then git checkout myBranch will succeed as an alternative to git checkout -b myBranch origin/myBranch. This is intended as a convenience for the common case of checkout out a remote branch for the first time, creating an identically named local tracking branch.
There are other possibilities, too, depending on what exactly you are using for completion, but that's one of the first things I'd check. If you run git branch -a, and there is an origin/myBranch listed (or one for a remote other than origin, if you have such), then that's a likely culprit.
Depending on your setup, there is another source of what might look like old or deleted branches - your git-completion may also be suggesting tags along with branches.
I was fooled by this recently - our CI/CD pipeline tags all our builds, and even though certain branches would be released and/or deleted years ago, the tags persisted. Cleaning up old tags on the remote was the solution here (there is a guide here).
(I answered this here as well - not sure if it counts as a duplicate as it's on StackExchange...?)

How to merge 2 branch in XCode?

We are two developer and we want to work on a same project at the same time. So, we use GitHub. However, we couldn't do this.
This is our problem;
I am pushing new xcode project to our master, then, my friend are pulling this xcode project. Every thing is ok since here. Then, I am changing some codes, then, I am pushing (commit and push) it again. When my friend change some codes (he didn't pull) and push it, there is an error like this: "The local repository is out of date. Make sure all changes have been pulled from the remote repository and try again."
Actually, we want that, we change some come codes, then, I and my friend push it, then these two file will be merged. How can we do this?
he will need to do git pull --rebase which will pull the branch and put his changes on top of yours
you should really branch each feature though and work on the conflicts during merge

Resources