Auto commit and auto push changes in local repo to git - eclipse

I have a local development system where I have a Ubuntu-Server VM and I use eclipse in windows host. I develop in eclipse using Remote System Explorer & SSH. I want that whenever I save a file or do some changes in ubuntu-server's /var/www/site-folder it automatically commits and pushes the changes in my git repo. I did try the google but it wasn't much of a help. Any help is appreciated guys. Really wanna improve my workflow.

This sounds like something you'll have to script. If you save as much as I do (a lot), then you'll end up with a lot of commits. Unless you're careful about when you save, you'll probably end up with a messy history, unless you squash things later.
Are you sure that you want to commit and push automatically every time you save? It also matters whether or not you're pushing to your own private branch or repo.

Actually I think there are use cases where this /is/ a good idea. If you work on two different machines (even not simultaneously), for instance, you cannot share the Eclipse workspace. One simple way to overcome this is to put a bare git repository on a cloud server (dropbox, copy, one drive, etc) and push all work, completed or otherwise, to that everytime you close eclipse.
Will the repo be messy? Sure, but that's not the point.
I could find no easy hooks within Eclipse itself to automate this so I simply put an invocation of Eclipse in a script and finished off with:
git commit -a -m "WIP commit"
git push origin
You just have to watch out for newly-created files and remember to add those before you exit.

Related

How to view file changes before pulling through GitHub on RStudio?

I'm transitioning from using Subversion in Eclipse for code management to GitHub in RStudio. It's starting to make sense, but I can't seem to figure out how to pull effectively.
Specifically, if I use the Pull arrow in RStudio, every file change in the repository automatically updates my local files without warning. I can see how many files were updated, but not what changed!
Here are the questions I'm hoping to get help with:
1) Can I preview the repository file changes in RStudio before I pull them locally? With SVN in Eclipse, there was an indicator showing files with a difference, and the option to view side by side.
2) If multiple files have been changed on the repository, is it possible to pull just 1 locally?
3) How can I revert a local file to a previous version?
Right now I've been trying to do this all within RStudio for simplicity. I haven't used things like the GitHub desktop client.
I appreciate the help!
I would suggest you better get used to the git's own tools to stay informed about your repository.
For example you could do following.
Before you pull, check your current commit logs
git log
This should show you how your current commits stack up. Note the latest commit id (first 4-5 letters would usually do)
Now after pulling you can see the difference using following command
git diff --color your_previous_commit_id..HEAD
If you don't like the changes and want to go back,
you can just reset to your favorite commit with following command. BTW run "git stash save" to keep a copy of your uncommitted changes.
git reset --hard you_favorite_commit_id
Note: that this will delete all your uncommitted changes unless you stashed them and put your local branch behind the remote repo branch you are tracking again.
Wondering where to put these commands? Check https://git-scm.com/downloads.
What's good about using these git tools is that if you switch between IDEs you don't need to search for same functionalities you had in your earlier IDEs.

Share project's code between PC and Notebook

Sometimes I want to be able to work with my php code both from my PC and notebook. I know, that I can use git, but I don't want to make dirty commits just to transfer code from PC to notebook and back. So, may be you have experience with it, what tools I can use to share my project between PC and notebook, may be I should use dropbox or something similar?
I still recommend to use git (or some other SCM of your choice).
You can deal with dirty commits like this
Create a feature branch for those commit
When you produced a reasonable state, then
Merge feature branch to your main branch or
Squash all dirty commits to the one clean commit and merge(or rebase) it with your main branch
if you dont want to use git or svn because of the commands You can use any of the cloud storage (onedrive, google drive, dropbox), these work well, I use all of them in some capacity and they are good. BUT youll always need internet in order to sync it accross. It will come down to preference and wheter any of these services are blocked by the firewall (in places like work etc if you want the code at work)

Git reset gives me "still trying to merge"

I've googled this in many different ways and can't find anyone else talking about it (at least as far as I understand).
On my office pc I was trying to find a solution to a problem I was having (so I was ahead of my remote git repo, but without committing).
That night at home I figured out the solution and pushed it to my remote repo from my home pc.
Now I'm back in work and I wanted to reset my local repo on my office pc to match the remote (and discard all my local changes).
I ran:
git reset --hard origin/branch1
I got:
HEAD is now at 1501f25 **Still trying to merge**
What does this mean?
'Still trying to merge' seems to indicate it didn't complete somehow, but I can't see how (and I'm having no luck finding a clear answer in the git docs).
If a git merge --abort (git1.7.4+, January 2011) doesn't do it, check if you still have a .git/MERGE_HEAD file (and delete it).
Then the git reset should proceed (or, since it completed, the git repo state should be coherent).
Make sure you are in the right branch you wanted to reset to origin/branch1.
As the OP Roy Collings suggests, recloning should get rid of the warning, but that means having one's project config files versioned in order to minimize the time spent to configure everything again in a new cloned repo.
Since relative paths are supported in an Eclipse config, having .project and .classpath in a git repo is possible.

Eclipse: How to export local history to a real SCM system like Git or SVN

I have an Eclipse project which started out as a smallish, quick'n'dirty, private hack. I did not bother to use a real SCM (source code management) system like Git or SVN, not even locally. What I have instead is a few days' worth of Local History, an out-of-the-box Eclipse feature. As so often, the project grew and I want to share it including history, because the history shows a lot of refactoring steps which come in handy as a showcase in order to teach someone else about refactoring, clean code etc.
I already know that I can manually retrieve old versions file by file and manually migrate them to e.g. a Git repository, committing changes one by one and file by file. But what I am really interested in is:
Can I reset the whole project (not just a single file) to a certain date using Local History?
Is there a way to export certain (or all) snapshots of the local project history, so I can commit them to Git snapshot by snapshot?
Is there even an option (or an external tool, script etc.) by means of which I can automatically migrate a project's local history to a real SCM system like Git (preferred) or SVN? It would also be okay if the tool just created lots of full project snapshots in subfolders named by timestamps.
Disclaimer: Yes, I do know that I should have used Git right from the start. It would have cost me just three minutes to set up a local repository etc. But... BUT. You know. ;-)
I don't think there is, but keep in mind that the task shouldn't be too tedious.
Make a copy of your project before starting, just for safety's sake and then:
git init
(revert to snapshot 1)
git add .
git commit -m "First snapshot commit"
(revert to snapshot 2)
git add .
git commit -m "Second snapshot commit"
Wash, rinse, repeat.
If you've only got a few dozen snapshots, it shouldn't take more than an hour or so to do, which is probably a lot less than it would take to figure out a programmatic solution.
Unfortunately, the answer is "no" to all of your questions. At least, using standard built-in Eclipse functionality; there's always a chance that someone has written a plugin that meets your needs, but in this case I'd be surprised. Check the Eclipse Marketplace (found under the Help menu).

Can I have git gui and git bash and eclipse git plugin looking at same repo simultaneously?

I am using Eclipse to work on Android java projects on a Windows 7 machine. I am using Git to version-track, back up, and share.
I have git gui, git bash, and the eclipse git plug-in. My question really comes down to:
Is it safe and/or will my tools (gui, bash, eclipse) work right if I have them all open and looking at the same git repo at the same time?
I ask this because I have had eclipse fail to do a checkin a few times, and one time in git gui when it was barfing I got brave/stupid and hit the "unlock git index" choice. Since I did that unlock, none of my git clients have complained. But the suggestion that there IS a lock and that I "manually" unlocked it has me afraid that I have opened the door to non-thread safe crashes in my git repos.
TIA
Yes, it is safe. The index lock is something that is normally only intended to be held while an operation is in progress (e.g. while a commit is being created or a merge is being handled).
If you have to manually unlock the index it probably means one of your Git clients crashed/errored while it was doing one of those operations and thus accidentally left it locked.