committed without git pull, not pushed due to conflict - netbeans

I am using netbeans to pull/commit/push to git. I have accidentally make commit before pull request and now it's asking me Rebase/Merge. Either of option gives me error. I tried with following links using Windows git shell
How to undo last commit(s) in Git?
How to revert Git repository to a previous commit?
How to undo last commit
Remove a git commit which has not pushed
I have tried following commands:
git checkout <commit sha key>
git reset --hard <commit sha key>
NOTE: I have commited change but not pushed!

try git reset --soft HEAD~1
when you haven't pushed yet, a soft reset will take all the changes from the latest commit, and place them back onto stage again. in other words, the status of your repo will look exactly as it was the moment before you commited.

Related

How to undo the most recent comment on git

While using git hub I wanted to delete/undo a comment that I had recently posted. But I was unable to do it. So I want to know how to undo the recent comment in git.
Here is one of the several and easiest way to do it.
First of all lets check commit history.
git log --oneline
Now in the output you will see a list of commits. Something like shown below.
241b8e7 (HEAD -> papers) Added paper-logic according to new requirements
8ae8f7d paper backend fixed
3c9a3ce toggle sidebar change added
af1af34 link to style tag added
Now as per your question you want to undo previous commit i.e you want your project to be at 2nd last commit.
So "code"(left of commit statement- "paper backend fixed" ) for 2nd last commit from the above example is 8ae8f7d. Copy this code.
To go to that commit enter the following in terminal.
git reset --hard <code>
What this will do is forcefully change all your project to the stage as it was on mentioned commit.
Note that it is irreversible i.e once you have gone to previous commit you cannot come to commits above it
You need to undo the commit as well.
Undo Last Git Commit with reset
$ git reset --soft HEAD~1
If you are not familiar with this notation, “HEAD~1”
“HEAD~1” means that you want to reset the HEAD (the last commit) to one commit before in the log history.
You can use this as well
$ git reset --hard <commit sha1 | reference>
$ git push --force
to check the commit hash and reference you can use
$ git log --oneline
or
$ git log
Undo Last Git Commit with revert
$ git log
$ git revert <commit sha1 | reference>
$ git push --force
You might want to check these as well
How do I undo the most recent local commits in Git?

Git revert and reset : Files in the repository are not getting rolled back

I want my entire repository to roll back to a certain previous commit (that is 20 commits behind my latest commit).
I tried using git reset --hard <commit#> and git revert <commit#>
Both the git commands run successfully with the message - Head is now at <commithead>
But then when I see the code in my repo, I can still see the edits I made in my latest commits. How can I remove all the edits after the particular commit I am reverting to?
Am I missing out on some step here?
After your git reset --hard, use to be sure the git restore command
cd /path/to/repository
git restore -- .
That should restore (as its name implies) the working tree with what is in HEAD (and you just reset HEAD to the right commit)

get previous commit that got deleted on git repository

Yesterday when I was at work, I was working on my project that i have on my home computer. The problem was when I tried cloning the repo it eclipse would crash. So instead I downloaded it manually and initialized the repo and then force pushed to my home computer. This deleted all the history and files in on the repo. I did some googling and tried reverting the commit but it the force push erased the commit history so I can only go back to the force push commit.
I have a computer at home which hasn't pulled the updates since this mistake and I was able to get its commit SHA. I used that on the web and found the last version its still there but I can't pull that commit because it got "deleted" and won't show in the repos history. Is there a way I can use the SHA from the last good commit and make that the master branch restoring my history?
When changing the HEAD (the working position in the git repository), it tracks your history in the reflog. Executing git reflog in the command line will show your complete history. You can read more about it on git-scm.com
When you have the desired commit SHA, you can do a git checkout with it. Executing git checkout [SHA1] will take you to the desired position in the git history. From there, you can make a new branch from it by running git checkout -b "new_branchname".
If you want to set your current branch to the commit, you can run git reset --hard [SHA1]. This would reset the current branch, but the previous state can however be found in the reflog.
I do NOT recommend doing this as general practice BUT...You should be able to force push from the other computer, thus resetting the repo to its former state. Providing you don't want to keep anything you did while making a giant mess of your git repo yesterday.
Since you know the right version you want to recover, it will make things easier.
In your local repo, use below commands:
git reset --hard <commit sha value>
git push -f
Note: if you execute the commands in the local not initialized (not cloned from remote), you should fetch first by git fetch --all, and then execute the two commands .
Now the version will go back to the latest as you need both locally and remotely.

How to revert / undo my last two pushes (commit and revert) in github?

I got a Github repository from client where there is no code.
I cloned this repository and pasted my code folder to this repository and pushed the code to git.
But now I need to revert back my commit. For this I did the following steps:
git revert xxxxxxxxxxxxxxxx(commit)
git add .
git commit -a -m "reverted back"
git push origin master
After this I went to my github page, there I find project folder with app/views, config, db, log, public, tmp folders where revert is not properly done.
How to undo my last 2 commits (both commit and revert) and get back to the main repository as it is?
Please help me, I am worried.
The simplest way is just to hard reset to commit preceding the bad one:
git reset --hard xxxxxxxxxxxxxxxx^
git push -f origin <your-branch-name>
There xxxxxxxxxxxxxxxx is your sha, that you reverted in the first time.
Note the ^ before xxxxxxxxxxxxxxxx. It means that you reset to the commit before xxxxxxxxxxxxxxxx.
Or you can specify exact hash to reset to, i.e.
git reset --hard A
Before resetting your branch is looking like:
A -> xxxxxxxxxxxxxxxx -> B(bad)
After git reset --hard xxxxxxxxxxxxxxxx^
A
git push -f origin <your-branch-name> pushes your local changes made on the previous step to the Github server
Be careful with force pushing though, because you force your local repository state on the server. So you lose server state forever

git / github unresolved conflicts but no visible differences

I am using eclipse, git and github. A friend of mine forked my github repo and changed some code. There was a pull request, I accepted the changes to my github repo. Now I tried to commit my own files and I am not able to 'commit and push'. As you can see in my screenshot there are no visible differences in the file. What procedure will solve this conflict?
Assuming your friend's work got merged into master and you are on branch your-feature-branch then:
git checkout master
git pull
git checkout your-feature-branch
git rebase master
will attempt to rebase your work on top of master, which already includes your friend's changes. The rebase procedure will process your commits one at a time and inform you of any conflicts which you can then resolve. Each file with conflicts will have conflict markers that tell you the changes introduced by each branch. After resolving the conflicts stage your changes then do
git rebase --continue
Repeat until rebase finishes. If at any point you become confused you can always abandon the rebase with
git rebase --abort
Once your work is rebased push your-feature-branch to origin, open a pull request, then merge.
I got the same issue sometimes, without a visible reason. Using a git rm on the directory containing the bad file, followed by a git reset --hard solved the issue for me.
git rm --cached -r DIRECTORY
git reset --hard