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

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.

Related

Comments in git (egit)

We recently moved to git from svn (both using Eclipse). I am in the (perhaps bad) habit of writing my Java code first, getting everything to work and then going back and adding comments. In SVN this was easy. I would just create a Fisheye review with my Jira task. The review would have a list of all the files I changed and methods I added or modified. I would note it and abandon the review. Then I would edit all the files listed and add the comments.
However, Fisheye does not (I believe) work with git. I could do a git status to see the files I changed but the local branch is already updated so it will not list any files. And all it does is tell me I am something like one commit ahead of the remote branch but does not list any files.
Is there some way to see a lit of the files I have changed with git so I can add comments? And when I say I wait for my comments I really mean mostly for added classes and methods. If I do something like add a line or two to a method I will generally add the comment too.
changing comments on git commits is not that easy. Each git commit has a sha-checksum which also includes the previous git commit. If you change a commit you change the current commits sha-checksum. therefore you create a new commit. All following commits of your branch must now be rebased on top of this new commit.
The command line provides the git rebase -i [commitid] where you can do lots of modifications including changing comments on commits. I never did this with a GUI but egit might support that too. Just refer documentation on egits rebase feature.
I found out how to do this.
The "Synchronize Workspace" in eclipse appears to show all the changed files not yet pushed remotely. I have not done any pushes, so this showed me what files changed.

Visual Studio 2015 with github plugin issue

I'm new to using github with visual studio 2015 plugin and I'm stuck.
I created a new project on github and was able to link the depot to my visual studio project. I was able to sync some code up to the depot.
Then I added a readme file to my project on github from the website. Next day I made more code and decided to sync it up to the depot, but now it says that I have incoming commits (the readme file). I clicked on fetch on the incoming commit but nothing happens. I clicked on pull and it says my changes would be overwritten by merge.
I then went to outgoing commit (the ones i just made) and click on push. it says that "You cannot push branch master to remote origin because there are new commits in the remote repository’s branch. Pushing this branch would result in a non-fast-forward update on the branch in the remote repository"
i click on several things and i still can't resolve this issue. I want to update my current project with the readme and then update my depot. (i also am new to the terminology)
The trouble is that you've got changes on the server, that are committed, and changes to some of the same files on your local copy that conflict with it to the extent that Git can't figure out which ones should "win".
You'll have to look at each file that has conflicts, understand where the conflicts are, sort them out, tell git that you've sorted out the file, and then progress.
So Fetch will bring all of the changes down from github, locally, but not change your working copy.
Merge is intended to pull down the changes in your current branch and merge them in (and that's where it's having trouble).
Best recommendation for working with git (whether Visual Studio or not)): Fetch and merge often. Every day at least.
This page looks like a reasonable tutorial on how to do it. It looks similar to my VS2015 git plugins.
https://msdn.microsoft.com/en-us/library/dd286559.aspx
This page is quite a good tutorial on doing it from the command line:
https://easyengine.io/tutorials/git/git-resolve-merge-conflicts/
(But I've got to say: the Visual Studio tool makes it easier).
So the key points are:
look at each file and fix the conflicts.
tell git that you've fixed the file
Once you've done all the files, you need to "commit the merge"
Then you're in a place to commit your local changes and push them up to the server.
Second tip: Most people that I know who use git with visual studio also use the command line client extensively, and usually have an additional gui client (such as Atlassian's Sourcetree) as well. I use all three every day.

EGit: How to restore git to to the clean state

I read few threads on backing out commits. Following are relevant
How to delete commits with egit?
What's the difference between Git Revert, Checkout and Reset?
But how do I revert/reset/restore back to clean original state. I just started working on new project and the original git directory structure got messed up after the first check in (because I incorrectly created git repository as eclipse project); this problem is discussed in "The short story" or "The longer story" of following link
http://wiki.eclipse.org/EGit/User_Guide#Creating_Repositories
Now I wanted to restore the original directory structure of git repo. In History window, I see all the previous commits and I can right click on them and back out to one of previous commits; sadly the history window doesnt show anything to prior first check in (or commit). But I want to back out to the original directory structure that existed prior to first commit (that way I will have clean repo without any code base in it). It doesnt matter if it is restore/reset/revert as long as git repo looks same as it was before first committ. Can I do this in eclipse/egit?
This isn't something that Git would have kept track of.
You might look into the Eclipse local history (which is separate from the history recorded by Git), but that is for a file only. Not a all structure.
It is best to recreate a Git repo, and make as a first commit your clean structure, before adding code base in it.
Go to git perspecive-> Expand the repo. Right click on working tree. Clean. Finish. See the below pasted image link.
clean in git perspective

Auto commit and auto push changes in local repo to git

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.

cvs: updates fail to merge

I've just discovered, a surprising for me behavior of cvs.
I change file1 localy
During this time people change other unrelated parts of the same file, and commit to the repository
I update my local copy from repository
At this point I expect my local copy of file1 to contain all changes made by others to this file, unless the update above reported a conflict. However, when I do now diff with head, I discover lot's of differences coming from changes made by others in parts of the file that I did not touch at all.
Any ideas? Is this just the limited abilities of cvs to merge? Any wrong setting? Something in my workflow?
CVS has very limited merge facilities. Switch to a modern system such as Git (perhaps via git-cvsimport if the repo maintainer is uncooperative) if you want a better merge experience. See also Best practices for using git with CVS
The final solution is :
1. Save your local code to another place manually
2. Revert the files which may has conflict to the HEAD (most latest) version on CVS server.
3. Add back your change to the Reverted file.
The concept for above solution is to CLEAR UP all the possible issue by REVERT and get a 100% clean version from repository then add back our changes.
It can resolve below issues which caused by code out of date / code base messed up.
CVS commit had a conflict and has not been modified
CVS update failed
CVS not sync