Git completely replaced changes in history. How to restore files? - eclipse

I have git repository on bitbucket. I use it from Eclipse for a while, but then copy Eclipse project with local git repository to another place on the filesystem and work locally for 3 weeks. I'm a newbie with git, so I just copy the project as is.
Yesterday I try to push local changes and then switch to the remote branch. Now I see in git-gui only old bitbucket commits and no new files. I search in git-gui everywhere. But the size of the repository tells me that my new files are still there (on bitbucket 16mb, locally >300mb).
git branch shows me 2 branches (master and * (no branch)) and both have bitbucket commits. I didn't make any branches, I just first cloned the repo from bitbucket, then made commits, then made some actions trying to push the copied repo and then change branch. Any idea of how can I restore my local files will be greatly appreciated!

I'm really having a hard time understanding what the exact situation is.
However, if you say all the files are still in the local repo, a simple:
git reflog
is all you need to see recent commits on all branches. Find the right commit you want to go back to, and take it from there.

Related

How do I merge a old changes into a Git repo?

I know this is a common question, but I can't find the answer I'm looking for.
I have a GitHub repository that receive a few bug fixes that I merged into master.
But I have 100s of change in a local folder, and I want to merge the changes with the master.
What I am confused about is where do I start:
Do I create a branch, then drop my new files into that branch folder on my hard drive, commit the changes to this branch, then merge the branches?
If you are the owner of the GitHub repository and have its latest master already cloned, you could simply:
copy over those changes in your local cloned repository folder
git add/commit and push (no merge needed, since you are the owner)
Not that there is no "branch folder": the folder would be the same as your local cloned repository folder.
You can, if you want, make a branch for those changes, in order at least to add/commit those 100s of changes in smaller commits, helping to build a coherent history (instead of one commit, with as commmit message "giant dump of change").
But that would be in the same folder as your currently cloned repository.

How to merge local folder and its structure to github?

I am still a beginner and I locally made a folder of my Project and uploaded it as a repository in GitHub using GitHubDesktop. Now I changed the structure of the files (deleted some sub-folders and moved files here and there locally). Now I don't see those changes in my GitHubDesktopas something which I can push to the GitHub online and reflect the changes there.
I am not sure how to achieve that:
(One way I can think is to reclone and download the online GitHub repository to local, move the changed files again and then commit from GitHubDesktop) , but I am not sure if it will work because I did the almost the same thing just without recloning: but after the reorganization, the changes are not appearing in my GitHubDekstop which I can commit.
Any advice would be great. Thank you.
This is my repository (https://github.com/grammilo/Codes) whose organization I want to copy from a local folder which goes by the same name and was previously cloned from it.
When you go to the directory of the repository in your terminal, checkout your master branch
git checkout master
and use
git diff
this will display any changes made to the files and file structure in green and red. You can delete folders and files directly from your file system or from the terminal, whichever you prefer and these changes will display when you use git diff. After your changes are made use
git add
this will stage your changes to be committed. You can use
git status
to make sure your changes are ones you would like to make.
Use
git pull
to pull any changes from your repository and when you are ready to commit your changes simply use
git push origin master
this will commit your changes to the remote repository on GitHub from your command line without using GitHub Desktop. Check out the git documentation for more in depth explanations but that should achieve what you're looking for.

Committing changes to branch I got by downloading zip from GitHub

I'm working on a repository that has two branches: Master, and Release1.
The branch I need is Release1. I went to the site and tried to clone it, but no matter what I did I got the Master branch cloned.
So I gave up and downloaded the branche's zip to my file system. I added it to Eclipse and worked on it.
Now I need to commit my changes. But neither the branch nor the repository show up in my visual tool.
When I try to add a local repository the visual tool tells me the folder is not a repository.
Is there a solution? I have quite a few changes on my local project and I have to commit them.
The Zip download is not a Git repository, it's only a collection of the files at that moment in time. Here's a way you might be able to get your changes into the repository:
Clone the repository properly
Copy your current files into the cloned directory
git status and git diff to check that the changes are what you expect
git commit
When you cloned the repository the first time, you were getting both branches - a Git clone is a fully copy of everything: every branch, all history, etc. The default branch is typically master. After you clone, if you want to switch to the other branch, use git checkout Release1.
What GUI are you using? When trying to clone you have to make sure you change the branch you are cloning from (usually in a drop down menu or you may have to type it in). If you can successfully clone from Master, than you should be able to change to or "checkout" Release1 branch.
Just downloading the zip, just gets you the source code and doesn't have any connection to git. To save and push your changes you will need to clone the repository and checkout Release1

Stopped Using Git - Now Want to Start Again. How to Get Synced Back Up?

We had a number of developers working on a large website project using Git. We have a GitHub repository and then we have the website on the server, plus all the developers have their local versions.
When we finally launched the project, I got lazy (hangs head in shame) and started making changes directly to the server, without pushing them back to the Github repo. However, other people made changes to the repo, for reasons I don't quite understand, that were never pushed down to the server and are now either outdated or wrong. We have been doing this for almost seven months.
Now the server and repo are hopelessly out of sync. I would now like to get the most updated version of the site (which is the server) back up to the Git repository so we can begin another round of development. I basically want to start with a fresh copy of what is on the server.
How would you recommend I proceed? That was the first time I had used Git. It didn't seem like such a big deal at the time but now seems like it is harder to start up again than I thought.
I have looked for instructions and don't really see anything that fits. Because I am not super confident in my Git skills, I am afraid to just start trying the few ideas I did find and losing what I have on the server.
(I know I could restore from a backup if I really messed it up but would prefer not to do that as it would take the site down.)
Can I uninstall git and start again with a fresh repo? Or is there a safe way to push the current version up to the repo?
Thanks for your help.
UPDATE: I found this answer elsewhere (Replace GitHub repo while preserving issues, wiki, etc) but I am not sure how to do this:
cd into "new" repository
git remote add origin git#github.com:myusername/myrepository (replacing myusername & myrepository accordingly)
git push --force origin master
Possibly delete other remote branches and push new ones.
Not sure what they mean by "new repository"
Make a new branch and push it to GH.
Make a new branch based on the previous
branch.
Switch to the new branch (created on #2).
Delete all the files and folders on this branch repository
except the .git folder and contains
(maintain the README.md,
.gitignore and other files if you want it).
Copy all the files from the server except
.git folder.
Commit.
Switch to local Master (created on #1)
Merge this new branch with the previous one.
Solve conflicts
(I use SmartGITthat have a visual conflict solver and helps me a lot, but you can use gitdiffif you don't want a visual interface)
Commit
Push it to GH.
I hope this helps
I figured this out. What I did was:
Make a new branch on Github to effectively store a backup.
$ git add . to stage all changes
$ git commit -m "Commit message" to commit changes
$ git push --force origin master to force changes from server to remote branch master
Once I did this, there were still hundreds of files I had deleted on the server that were not reflected on the remote github.com repository. I used the following:
$ git rm $(git ls-files --deleted)
See Removing multiple files from a Git repo that have already been deleted from disk
Then repeated git commit and git push. Now my github repo matches my server exactly.
I have not yet deleted the "backup" branch I created on github but I will.
Hope that helps someone.

Git/Mercurial locally ontop of local cvs checkout

I have read :
"Best practices for using git with CVS"
"How to export revision history from mercurial or git to cvs?"
, and neither suit my needs.
At work we use a remote CVS repo. Access to this repo is handled via eclipse CVS tools, and in-house eclipse plugins that are built ontop of team tools for eclipse. This means we can't move to a better vcs.
However I would like to use Git on my local machine (to enable personal branching) such that I can accomplish the following:
Create branches in Git and then once finished and merged back into my local trunk, commit back to the cvs repo using the eclipse team tools etc.
My plan is something along the following lines:
Copy the checked out files to another folder [gitRepo].
Create a master git repo in gitRepo
Branch in gitRepo and make changes.
Commit to gitRepo
Copy gitRepo back to checked out files
Sync with remote cvs.
I was planning on using eGit for eclipse however I believe that the CVS and .git files will compete for ownership of the versioning.
Are there any tools or suggested work flows to help me manage this? Also how well does Git play with CVS files. And vice versa since I don’t want them to infect each other.
The reason the former links are of no use is they commit straight to the cvs repo from the git repo and this worries me as I do not wish to infect the cvs repo by accident.
It should also be said that changes in the GitRepo do not need to persist into the CVS repo, for example I don’t need to see every push to the git repo reflected in the remote CVS.
~Thanks for reading.
You perfectly can create a git repo directly within a CVS workspace (much like directly within any other VCS tool.
Make sure git will ignore any .cvs resources, and make sure CVS will ignore the .git.
Any Git commit won't be directly reflected in CVS.
The only trick is for Eclipse to display only Git or only CVS informations and label decoration.
For that I would configure two different Eclipse perspectives in which I will de-activate one or the other VCS tool.
I have done exactly this at work and I found the following practices helpful:
Keep any one (master in my case) branch always in sync with CVS. Do not use this branch for your development. Periodically update this branch to get the changes made by the rest of the team. If these changes are relevant to your current work do a merge master from your dev (or any other appropriate) branch.
When you are ready to check in to CVS switch to the master branch and merge the changes from the appropriate branch (dev, feature etc. as appropriate). Run your tests!
You employer most likely will keep a back up of the CVS repos. You will have to find a way to keep your git repo backed up. One way is to add a mirror repository in a Dropbox folder and use a post-commit hook to update it after each commit.
Before you leave work switch to the master branch. I once made the mistake of running CVS up -d on a dev branch in the morning and ended up quite confused. Adding a script to automatically switch to master before updating helps.