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
Related
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'?
I accidentally deleted all my files by committing a new build, then deleting that commit. (git commit -m, git reset -hard HEAD^). Then I tried to use (git merge ) to undo the delete. I noticed that all the missing files were back, but all the contents were missing. To clarify, all the files that were missing after I deleted the commit was back, but contents of those files only included default Xcode markups and all my coding was still missing. Is anyone familiar with an issue like this? Any guidance would be greatly appreciated..
Steps:
git commit -m
git reset -hard HEAD^
git merge
You should be able to use git fsck to see any dangling blobs or commits which remain after a reset.
git fsck --cache --no-reflogs --lost-found --unreachable HEAD
You'll see something like this with any dangling objects:
Then just do git show with the blob id to inspect
git show fd2274ea24e214457fa865e6aa74a0a1b036291a
If it's the file you want, you can then write it to a file using git show {blob id} > filename. e.g.
git show fd2274ea24e214457fa865e6aa74a0a1b036291a > test.txt
I've just updated my Xcode from 6 to 7 (and code from Swift 1.2 to Swift 2.0) and try to create new branch in Xcode. After that I can't push my code to Bitbucket.
Is there a way how can I delete repository from directory and setup Bitbucket again and maybe push to another (a new one) repository? Fix of this problem will be great, but I will be satisfied even with move to another repository.
I had this error in xcode 7.1 on a year old project that was working fine. In my case I have a project with the default local repository created by xcode. For anyone who is not going to re-install and re-setup. It is possible to find out what the dangling command is and fix it from command line.
To find the dangling command Open Terminal from the project directory:
xcrun git status
In my case the status returned:
On branch master
You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")
To fix the problem I used:
xcrun git rebase --skip
In my case I ran git status which revealed that You are currently bisecting. (I was doing a bisect and must had forgotten to reset). I did a git bisect reset and attached the head to my latest commit and it was all fine afterwards.
When I am merging from currentBranchA into branchB, I got conflicts,I didn't want to solve the conflicts immediately and quit the merging process. But when I try to merge again, the Xcode shows "The working copy is currently in the middle of another operation..."
I opened the terminal ,cd to the project directory, and check the git status:
git status
it shows:
On branch currentBranchA
Your branch is up to date with 'origin/currentBranchA'.
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Just do it as it says. Continue to input
git commit and click Ctrl + C to close the commit message window.
The problem will be zero.
The problem was with installation of GitHub. I had a master repository. After reinstall and resetup everything works like before.
EDIT: For anyone who has a problem with Xcode and GIT I have a best advice. Don't use it. Use for example Source Tree
When you start developing for a living, you are gonna have to use more reliable solution for GIT. Imagine you have 70 branches. Using Source Tree you can easily solve conflicts and other things about working in team. Xcode GIT solution is not reliable and you are gonna be only frustrated.
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 :)
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.