How to restore a file from another git repo - laravel

I have a project uploaded to the server and I deleted one of the project files by mistake, now the project is connected to the git and I want to restore the file that I deleted from the copy of the project on the local, what do I do?
I tried to make "git pull", but I got "Already up to date."

If you have not staged the deletion yet, simply run git restore <filename> and the file will be restored from the index.

Related

How to recover .git folder deletion?

I accidentally deleted my .git folder, I would like to recover the .git folder, but I permanently deleted it.
Will I lose all my project's history?
I also tryed the following solution with no success.
Notes:
It happened when I imported the code to the Eclipse IDE.
I made many local changes without pushing them.
I also using GitHub as a repo.
Using Windows 10.
If you have pushed your changes to GitHub, then all your history is sitting in the repo on GitHub. You can clone the repo again.
If you have not pushed your changes to a remote repo, then the only place that those changes existed is in your local .git directory in your project directory, and those changes are now gone.
I had to re-clone the repository and paste the .git folder in the recently cloned project, into the project's folder.
So I only lost the local commits.

Why are subfolders not being seen by the Git repository?

I have just created a local repository (using Git) for a project that will contain many subfolders (it is a pedagogical project with Lesson 1...2...3 etc..., each one with a folder within the main directory).
I connected this to the remote repository I created on GitHub.com and hoped that would have been enough to start working, pushing, committing etc... now that I have created the first Xcode project inside the main folder neither Xcode Commit function nor Terminal git commit command is seeing any change.
The symptoms I see are that the remote repository sees "Project name" folder, then "Lesson 1" folder inside it but nothing else inside "Lesson 1", where the Xcode project should be (it actually is there in the Finder).
What may have gone wrong?
What would have been the proper set of actions to create a repository in a directory that would automatically fetch every new file added to it?
Thank you so much!
Git will not automatically track new files you create in the directory tree which contains your local git repo.
When you create new files, you need to inform git that you want them tracked, with the "git add" command.
git add path-to-new-file
If you create new files and do not add them, then when you run the "git status" command the output should contain a section labeled Untracked files, like this:
Untracked files:
(use "git add ..." to include in what will be
committed)
asdf.txt
It will show the path to the file(s) relative to the top of your git repo, including the filename(s). Pass all of that to the git add command. Then commit, just as you would for changed files.

I have deleted my project.pbxproj file using git checkout -- <file>. Should I delete the branch locally and pull from origin?

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.

git delete all files form remote branch after updating .gitignore

I recently started working on an open source project called "TFDT : Team Foundation Dev Tools" but I made a mistake to add a std .gitignore and now I want to fix it by adding one from https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore
I've already 10 or so commits by now and I've two branches. Is it still possible to get rid of all undesired files from GitHub's both branches that I've now ?
At the same time I also want to make sure that if someone clones my repository, they should be able to build successfully as long as my code builds on my development machine.
Compatibility : VS 2k 8, 10, 12, 13
One solution I have done is to rename the files, check them in, then rename them back to the original file name and check them in again. For example, if you want to gitignore a file called config that is already tracked, add it to .gitignore then:
git mv config config.temp
git commit -am "renaming file for gitignore"
git push origin master
git mv config.temp config
git commit -am "renaming file back to original name"
git push origin master

How to recover files in git repository

I had a project connected to a local git repository. I decided to reinit that after some mess with branches and commits. Firstly, I deleted old repository with "rm -r .git", and than created new one with "git init". After that, I found out my work directory looking the same way as if my project was only created - the results of all my work are gone.
Trying many recipes from the internet didn't give results. Please, give me a cue, is there any chance to recover my project's files or not.
In the case your "local repository" means you did git clone /path/to/your/local/repo, yes you can restore it by cloning again with git ckibe /path/to/your/local/repo, or git remote add origin /path/to/your/local/repo && git fetch && git pull origin/master ).
Same thing if you cloned from a remote repository.
Otherwise, there is no way to recover your files with git, except if you removed by a graphical interface (which move to a trash folder instead of making a real deletion) or if you have a back up.

Resources