Git push without pull - java

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.

Related

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.

When I try to update project from git I get this error: Couldn't save uncommitted changes

I'm new on the job. I work as a junior java developer. We use Intellij IDEA java development editor, git(atlassian) and jira. I have a problem with git. This problem is when I try I get an error what is say "Couldn't save uncommitted changes.
Tried to save uncommitted changes in stash before Update, but failed with an error.".
Here is the screen shots of my git configuration and errors.
Go to this repo from git bash.
Then run this command (to check your current unstage changes) :
git status
Then apply below command to stash them :
git stash save "give proper comment to identify it later"
Now to check your unstage changes are in stash or not run this command :
git stash list
Now, you can pull your latest changes from your remote branch. (git pull)
To reapply your stash after pull :
git stash apply stash_id
(here, stash_id is like stash#{n})
I had the same issue. My solution was to set the global git config!
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe#example.com
After that IntelliJ worked fine again.
Your IDE is trying to stash your changes before he does the merge (pull = fetch+merge) and fail to do it.
It is something like this:
Tried to save uncommitted changes in stash but failed with an error.
The easiest thing is to open git bash, check the status and then stash, add or discard your changes.
Few notes:
Intellij has something internal called shelf, its similar to git stash but the files are stored and handled by IntelliJ and not by git, so keet this in mind if you decide to stash (shelf) within the IDE.
I have fixed this issue.
First open your project in explorer , then right click and open Git bash for here.
then apply command git stash pop.
this will clear the stash entries and you will be able to update your project now.
Just experienced the same issue with Android Studio. Using <Git Directory>\cmd instead of <Git Directory>\mingw64\bin as path to the Git executable solved the problem for me.

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.

How to Import github project based on commit history

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

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