How to Import github project based on commit history - java

I have project in github. I have committed a irrelevant code in repo. So due to this my app is not working. So i need to import the project without the last two commits. How is this possible?
I am using eclipse IDE and java language code.

I'm assuming that you committed the last two commits locally. Then you want to do a hard reset to go 2 commits back. You can make a backup branch of the two commits in case you still want them later:
# Make backup branch
git branch backup
# Do a hard reset of the current branch
git reset --hard head~2

You need to grab the repo and reset back 2 commits. The best way to do this is to checkout the repo locally:
git clone https://github.com/user/proj.git
and enter the repo.
git reset --hard HEAD~2
and
git push origin master --fast-forward
The last line only if you want to remove the commits.

Thanks for your answers. I have found the answer in IDE iteslf.
Right click the project -> Team -> Show in History -> (A small window will open, it will have all the commits with the caption) -> Again right click on the commit that you need to import -> Click Checkout

Related

How to “abort” merge in IntelliJ Idea version 21?

I use IntelliJ IDEA the latest version with Git.
I have created a new feature-branch and changed some things in the pom.
The same time other colleges worked on master, and they have pushed their changes into master.
I did merge my feature-branch to the master and pushed, and it succeeded. Now because of JDK 11 compatibility problem on Jenkins I should abort my merge which I have already pushed.
Anyone knows how should I revert it in IntelliJ IDE?
You can't just abort your commit, but you can revert all changes that were provided by your commit. For this, you need in Intellij idea open git log -> select commit that you want to abort -> select option in the drop-down menu `revert commit -> commit changes -> push changes. You will add a commit that reverts your changes

I've commited and pushed a new feature_branch on git but it doesn't show the changes on that branch after commit/push in central repository on github

So at first I just created the new branch in IntelliJ on the fly, made the adjustments to the code, push/commit the file. immediately after that I checked the central repository on github and there was no such branch. So I created the same branch directly on the github page, and when I tried to commit and push the changes this time using gitBash (even though I don't know if there is a difference) I got this message: "On branch feature_branch
nothing to commit, working tree clean"
I checked the central repository and my changes still weren't there. I've lost a whole day going back and forth I even reinstalled intelliJ.
Also I think it's important to note that the file I commit had several errors (it's like the class that I was working on had no Idea of other Classes in the same package), and intelliJ wasn't showing compiler errors when I wrote the code... I tried checking the Build Project Automatically checkbox in settings and it still doesn't work... I tried changing the project SDK, still doesn't work.
Could the problem be in IntelliJ, and if so, where and what should I look for? I'm completely lost and need some help. Any ideas on what should I try are welcome.
Check git log if there is your change comitted, check git status if there is anything left to commit.
Try to check also your current branch git branch if you are on feature branch.

Git push without pull

I'm making a school project with my class mates, and one of them has broke the main of the program and he push it to github. I have the project without the main modified and it works perfectly. Is there any way so I can push my files without making the pull, and replace the bad ones with mine?
If the other dev has pushed relevant changes, you should not just wipe them out, but merge in both of your changes.
The best solution, provided the dev has push other meaningful changes, is to just resolve the conflicts, and fix the broken code.
From your diverged commits, move them to a new branch, then merge back into master - resolving conflicts when you do.
# Create a new branch with your commits
git checkout -b featureBranch
# Get master from origin
git checkout master
git pull origin master
# Add in your changes
git merge featureBranch
# Resolve Conflicts
# Push to origin
git push origin master
If you truly want to just erase his commits ( which I do not suggest you do ), you can just force your push - this will overwrite everything on the server with what you have on your machine.
Every other dev who is working on the project will need to take additional actions on there end, as you are now changing history; this is not advised.
git push origin master --force
There is also a revert method; this will create a new commit that completely reverses the changes of a chosen commit; to use this, you first need a clean working tree.
# Move your commits to a new branch
git checkout -b featureBranch
# Get latest changes from master
git checkout master
git pull origin master
# Create new commit that reverses the other devs changes
git revert hashToRevert
# Pull in your additional commits
git merge featureBranch
# Push to master
git push origin master
You can probably use git revert command to revert that commit. This will do a new commit that undoes all the changes made by that previous commit, documentation here:
The git revert command undoes a committed snapshot. But, instead of
removing the commit from the project history, it figures out how to
undo the changes introduced by the commit and appends a new commit
with the resulting content.
Once done, you can push youw own changes on top of reverted commit.

Arrow up and number on Eclipse meaning

I'm working on a project using Eclipse with Maven and Bitbucket. Right now I can't do any commit, I mean even if I press the commit button, I can't see it on Bitbucket. Furthermore, next to my project's name I got a symbol with an arrow up and the number 2 next to it.
What does it means? What should I do?
This means your local branch is two commits ahead of the remote one. Git is a distributed version control system. The git commit command only introduces the changes to your local repository. To make them appear in the remote, you have to use git push after committing your changes.
Alternatively, you can use Eclipse as a GUI to perform the same steps. In the context menu that pops up when you right-click the project, there should be a Team option. Clicking it brings up another context menu, which should have a Push option.

eclipse mercurial conflict after pull: how to pick remote file

I have a repository at bitbucket and I was pulling a changeset from it to Eclipse using Mercurial plugin. Some of the files in Eclipse were modified, so it causes conflicts.
I just want to give up local file and update it with remotes. So I right click project and choose Team - Synchronize with
But what should I click to select remote file and give up a local?
Just right click on the file and select Revert.. as you want to discard your changes.
However in general, if you care about your changes uncommitted workspace update is not recommended. Instead commit your changes first and then rebase or merge after pulling.
Revert - this removes uncommitted changes. It makes the file contents the same as they are in the latest commit
Update - this moves the working directory towards the newest topological head on the current branch.
Rebase - this moves a committed changeset from where it was originally committed so that it becomes based on the target changeset. If in doubt use merge rather than rebase as rebase is an advanced operation.
The problem with uncommitted workspace update is that if there are conflicts there's no easy way to get back to the previous state. If there are conflicts with merge or rebase and you don't want to resolve them now you can press the Abort button in the Mercurial Merge view and it will go back to how it was before.
In Eclipse I can do
right click on file in Package Explorer
Replace with
Another Changeset
select the latest changeset from Remote repository

Categories