Comments in git (egit) - eclipse

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.

Related

How to correct «unable to merge unrelated histories»?

I use github desktop (https://desktop.github.com ) while developing the application with several other people, so, for some reason, when trying to merge two branches into one, the error "unable to merge unrelated histories" is displayed for one of the target branches.
What could be the problem?
First of all: You may also be able to find a solution using the search.
Potential reasons for the error message
From: https://komodor.com/learn/how-to-fix-fatal-refusing-to-merge-unrelated-histories-error
Here are some common scenarios where fatal: refusing to merge unrelated histories can occur.
You have a new Git repository with some commits. You then try to pull from an existing remote repo. The merge becomes incompatible because the histories for branch and remote pull are different. Git sees the situation as you trying to merge two completely unrelated branches, and it doesn’t know what to do.
There’s something wrong with the .git directory. It may have been accidentally deleted at some point or got corrupted. This can happen if you’ve cloned or cleaned a project. Here the error occurs because Git doesn’t have the necessary information about your local project’s history.
The branches are at different HEAD positions when you try to push or pull data from a remote repo and cannot be matched due to a lack of commonality.
Options to resolve the issue
The article describes two options on how to resolve/avoid such issues but targets command line /terminal users. I guess I would prefer option 2 over option 1 anyway, also using git in the terminal.
The article explains it like this:
The alternative (and longer) way of fixing refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone. This will ensure that any conflicts that you may encounter in the code are addressed before merging and prevent application errors from occurring.
How it (should) work in GitHub Desktop
In GitHub Desktop you should be able to use a modified version of option 2:
To unstage all the files in your last commit, double click staged files. This moves them to the unstaged area. Learn more in this GitHub issue.
To stash your unsaved files, right-click an unstaged file. Learn more about stashing files.
This will give you a clean working tree to pull your remote repository into. Once you’ve successfully pulled into your branch, you can:
unstash your files (see link above again) to reapply them to your current working copy.
commit them as a separate commit.
resolve any file conflicts that you may have.
I hope this explanation adds some clarity. Let me know if there are any wrong or misleading information in my text please.
This problem has several reasons.
But probably your project clone just differs from GitHub (main project).
First of all, save your project (because you probably don't want to code everything again).
Remove repo from GitHub desktop (not GitHub!!!)
Go to the project page in GitHub
Click code, open with GitHub Desktop, and code again.

How to merge deleted/changed file in eGit

The case:
Locally, I have a commit where I have deleted a file. Remotely, someone else have changed this file.
Now, when I merge, I find that git has the put the changed file in my working tree. This is probably the way git works, and in git command line, I'd be able to use git mergetool to choose between the deleted or changed file.
In eGit, however, how would I make this choice?
We ended up with a quite unusable work-around where we first addded the file to the index and then deleted it in working tree and then saved this change (deletion) to the index.
Technical info:
The version of eGit (feature) we're using is 4.9.2.201712150930-r.
The version of git we're using is 2.16.1
Background:
My team have recently moved to using Git as our revision control system. There's a general wish from team members to use an integrated solution and since we're working with Eclipse, eGit seemed to be the way to go.
I would suggest that all your team members follow this process:
Commit your changes to your local repository.
Pull with rebase to merge with the remote origin branch.
Resolve the conflicts, if any. In your case, if you deleted the file before the other team member modified it, then that person would have noticed that the file has been deleted.
Push the commit upstream.
This process has worked for us. Hope this helps.

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.

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

egit pull with uncommitted changes

I'm working on a project in Eclipse that was cloned from a GIT remote repository. The Eclipse eGit plug-in allows you to get going without really understanding anything about GIT, which is where I was. I've eventually realized that when I do a "compare with HEAD revision" I'm not as I first thought comparing with the remote repository, but with my local repository. I understand now that I need to pull updates from the remote repository, but it's not clear what will happen to my local changes. I've not committed these changes, partly because I thought I might be updating the remote repository (I realize now that I won't) but partly because I find the Package Explorer file decoration (">") is useful in identifying the files I've modified. If I commit then I assume these indications will disappear.
My questions:
How do I update my local repository without losing my changes?
Can I do this without losing my modified file indicators?
Update: I thought I understood how some of this worked, but I'm really lost now, particularly by the relationship between workspace and (local) repository.
I used Team->Pull to update my repository. Since I've not committed any changes, I expected this to work without conflict, but it flagged up all the changes between the workspace and repo as conflicts (confusion #1).
I assumed I needed to use Team->Synchronize to bring changes into the workspace, as I would with other VCSs. When I do, I see the changes, but not even the non-conflict updates have been applied to the workspace and there is no "Update" operation to do this, so I don't know how to apply them (confusion #2).
For the conflicting updates, I manually merged the changes into the workspace copy and used "Mark as merged", but this seems to do nothing. The conflict is not cleared. I would expect at this point the change would just be an uncommitted change in the workspace (confusion #3).
I read elsewhere that to remove conflicts I should use Team->Add and Team->Commit, but I don't want to commit my changes as I explained originally (confusion #4).
You can see I'm confused! Any help will be much appreciated.
If git pull does not work, you can use this:
git stash
git pull
git stash apply
not sure eclipse supports stash, so you may have to use the command line.