In Eclipse/EGit is there a way to edit commit message of unpushed/local commit? - eclipse

Using Eclipse/EGit how do I edit a commit message of a commit I've made locally, but haven't pushed to the repository yet?

That would be the "Amending Commits" section of the EGit User Guide:
open the Staging View or Commit Dialog again and select the option Amend previous commit in the toolbar.
See also this tutorial:
Git amend allows to adjust the last commit.
For example you can change the commit message.
The Git Staging view allows you to perform the Git amend command via the highlighted button in the following screenshot.
See more about git commit --amend in general at "The git commit --amend Command".
99sono adds in the comments:
I use:
Team Synchronizing Prespective > History View > Modify
(submenu) > Reword .
Finally this opens a popup where I can edit the old commit message.
See "Add ability to reword and squash commits directly from the history view"

You can select the commit and right click, then:
Modify -> Edit
to rebase onto that commit, amend it and then continue.

Related

Eclipse Egit. Checkout creates new commit. Why?

As I understand GIT, when I checkout on commit, I should get its files copy in my work directory, but no new commit should appear. Though when I use EGit and checkout on commit I see new commit in reflog. Why? As I understand checkout should not create new commit. Right?
Here I right click on commit and choose checkout
Then I get new commit in reflog:
So now I have few commits in my local master, but I never asked to do them.
Git integration for Eclipse - Task focused interface 4.6.1.201703071140-r org.eclipse.egit.mylyn.feature.group Eclipse EGit
You have to work with the History view instead of with the Git Reflog view (see git reflog and toniedzwiedz's answer for details):
Tell the History view which history should be shown: e. g. in Git Repositories view right-click a repository and choose: Show In > History.
In the History view enable the option Show All Branches and Tags (right button in the view toolbar). Otherwise, only commits of the current branch are displayed.
You don't see a new commit in the reflog. What you see is an updated position of HEAD. You changed it to commit 4b0d96a when you checked it out. When you check out another commit, branch or a tag, you'll see yet another entry appear in the reflog.
Try switching between two branches repeatedly and you'll see the same two commit hashes appended to the reflog again and again. This does not mean you're creating new commits. You just see existing commits being logged as recent commits pointed to by the HEAD pointer.
From the git reflog docs:
This command manages the information recorded in the reflogs.
The "show" subcommand (which is also the default, in the absence of any subcommands) shows the log of the reference provided in the command-line (or HEAD, by default). The reflog covers all recent actions, and in addition the HEAD reflog records branch switching. git reflog show is an alias for git log -g --abbrev-commit --pretty=oneline; see git-log for more information.
You may also find this chapter of the Pro Git book interesting. It offers a more comprehensible description of what git reflog does.

Revert git repository to prior commit using Github GUI

While there is loads of information available on how to revert to a specific commit using the git command line - e.g. How to revert Git repository to a previous commit?
Is there a way to achieve same using the github gui? There is a feature to revert the latest commit. However I was unable to find options from the Commits history to revert to a specific commit in the list:
on the right and here is what we see:
so there is no feature shown here for Revert to this commit.
Jump to the PR which is included in the commit which is to be reverted. Go to conversation section, there you will see revert option in front of all commits included in that PR (screenshot)
You can press the button on the side < > (like in your first picture) and with this you can browse the repository at the time after this commit. Now you can create a pull request or you can download the repository at this very point in time.
I guess there is no other solution if you really want to achieve this in the browser. In GitHub desktop there is the Revert button for each of your commits (screenshot).

Github with eclipse error [duplicate]

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;

How do I revert all files to a previous commit using EGit?

I am using EGit 2.2.0.20-1212191850-r with GitHub. All of my local files are committed and pushed. There is only the master branch. I would like to permanently revert all of my files to a previous commit (not HEAD~1). How do I do it?
Here's what I have tried:
I opened the History pane, where I see all past commits.
I right-clicked on the earlier commit and selected Reset > Hard.
I see the old version. I try committing the old version but none of the changed files show up in the Commit Changes window, even if I explicitly add them to the index.
I also tried Checkout in step 2, with the same result.
Eclipse git checkout (aka, revert) is not relevant, since it is just about reverting to HEAD, not an earlier commit.
What I'd really like to do is create a new branch from the earlier commit, but I'll settle for reverting.
If you already pushed the commits, it is generally recommended to revert the commits. The reason for that is that revert will add new commits to the history instead of replacing the history, which makes it possible for other people to just pull instead of having to rebase on the replaced history.
So in the History view, select the newest commit you want to undo, open the context menu and select "Revert". Repeat for the parent commits. When you're done, push the result.
Also note that "git checkout" and "git revert" are different things, "git revert" creates a new commit that undos the changes of a previous commit. "git checkout" on the other hand changes the working directory or current branch to a commit. You may be confused because "svn revert" does what "git checkout" does, not "git revert".

Egit rejected non-fast-forward

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;