This question already has answers here:
How to discard everything in git
(2 answers)
Closed 8 months ago.
I faced a weird situation with git and I couldn't find a proper solution. It is a bit more complicated than how I described in title.
I got a new laptop and I just installed git and clone one of my repository from remote. While I was working I noticed that git is tracking my all root user folder as one repository.
You can see the details when I run the "git status"
Now the question how I can make git to not track any this folders or basically I delete this unnecessary repository from git? I already deleted all files about git in this main folder and tried "git reset"; but it didn't work.
What can I do?
Looks like I fortgot to delete a hidden folder of git
".git"
, I just delete this folder and now it is not tracking this folders anymore. There is not any git repository at this directory anymore.
I just answered because someone else might have some problem.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I did git reset HEAD -- "*user*" (to remove all "user" files from the staged area) but now git somehow thinks that I wanted to deleted a completely different file that I didn't even touch lately (the file is also still in my folder). git status now shows me:
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: webpack.config.js
I don't want to delete this file. So I want to remove the deletion from the stage and also from the index.
I tried all of the following commands which I found here on StackOverflow but none of these worked... (I of course checked git status after each command but the deletion was still there):
git restore --staged webpack.config.js
git restore webpack.config.js
git reset HEAD webpack.config.js
git reset -- webpack.config.js
git checkout HEAD -- webpack.config.js
git checkout HEAD webpack.config.js
git checkout -- webpack.config.js
git add webpack.config.js
git rm --cached webpack.config.js
At one point I also tried git checkout . which deleted all of my unstaged changes... (I was able to bring the changes back by issuing a undo command for each file in my IDE).
I also tried to unstage the deletion with SourceTree:
But this is also not working.
So what's the right way to remove a file from the staged area (but keeping the changes)?
The sequence :
git checkout -- webpack.config.js
git add webpack.config.js
should have been enough
I was able to solve my problem by clicking stage all and then unstage all again in SourceTree. The deletion is now gone.
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
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
I have just recently backed-up my XCode C++ project on my pendrive, using
rsync -avu
Since then, the version control for my project is grayed-out on every files, I can modify the files and not see the "M" nor the "A" sign. The only files still having version-control working "shared" files for which it works correctly. (Those shared files belong to a different project called "Shared").
I have tried git commit -m, git add . and even git init where the files were. Nothing worked.
Can you please help restoring version control for my project?
UPDATE:
Answers for the questions in commens (and answers):
my git repository is on my local hard drive.
I went to the Organiser-repository pane in XCode and I see my recent git commit -m "sth" as "sth" az a commit. I have a single branch: master.
Im not sure what command would be good to test git, as my commits work (theoretically).
I have a folder named .git in the project folder.
git log is working, showing the same as XCode Organiser-repository pane.
I think the XCode just can't synchronise with the git for some reason, and I don't know how to correct that.
First off, this is not an answer that will fix your problem, I just try to provide some help that might get you closer to a diagnosis.
Git stores its files in a folder named .git. Check if this folder is present in your project. If it's not then your Git repository is gone.
Next, try some basic command such as git log. For this to work, you must first cd to your project folder (or a subfolder thereof), because whenever you run a Git command it will look for the .git folder in the cwd or a parent folder. If git log does not work then your Git repository is broken in some way. Someone else will have to step in to further diagnose the problem, as I am no expert on this subject.
Finally, you should also check whether your rsync command has really sync'ed your project's .git folder with the backup's .git folder. Use this command:
diff -rq /path/to/project/.git /path/to/backup/.git
If there is no difference (as I would expect if rsync has worked correctly) then the problem with your Git repository is both in your project and in your backup. If there are differences then it might be worthwile to try your next steps on a copy of the backup (it should be fine to make the copy in the Finder).
Good luck.
I forgot to $ cd prior to deleting a .git directory and I happened to be inside Git's main folder, located on my hard drive at /usr/local/git.
I used $ rm -rf .git
I don't have this backed up with Time Machine, but I do have a three-week old clone.
This is not a tracked repository, just the folder that Git itself's files are in.
I figured there's no need for a .git folder in this directory. However, just to be safe, I did a $ sudo git init so the folder would be there if Git was looking for it.
Did I bork anything? Does Git even use this folder? Should I restore from the old clone instead?
Thanks!
Update - On re-reading the question, I realize you are not talking about a repository that you had intentionally created. The question doesn't seem to make sense. If there was .git at /usr/local/git, it might have been created accidentally while cloning or init of some repo etc. But then you say you had a 3 week old clone of it, which doesn't make sense. Anyway, if it is the former case, you need not worry. There shouldn't have been a .git there and git doesn't make use of it.
Does Git even use this folder - this is all that Git uses, because it is your repo. Unless you have clones of your repo elsewhere or have backed up your repo, you have lost your changes. Your 3 week old clone will let you recover some stuff, but any history that you had since then will be lost. Assuming you did not delete your working directory, you can still have your changes, but the history will be lost ( including any branches you had created in the 3 weeks etc.)