How can i do git rebase after git pull request? - github

I have a trouble git rebase.
because, I had pushed my local code to origin dev. And, I send a pull request to 'upstream'.
But, There are 1 PR and 7 commits like below the picture
I want to 7commits squash to 1 commit.
What shall I do?
( I have tried : 'git rebase -i HEAD~7', but I have met the message that 'error: cannot rebase: You have unstaged changes.' )

As per my comment, you must commit, stash, or discard all your changes before rebasing. If your changes are complete, you most likely want to commit them (git add --all followed by git commit).
If they are not complete but you want to continue working on them later, use git stash to save your unfinished changes while also resetting to HEAD. Perform your rebase and then recover these changes with git stash pop.
To instead discard all your changes, git reset --hard HEAD will do the trick; reset to unstage your changes, --hard to discard them, and HEAD to specify the commit to which you are resetting. You should then be able to rebase.
It's worth noting that a stash or reset will not affect untracked files. To have these files included, you must first stage them with git add.

Related

how can i revert git pull, how to bring repos to old state

1347
Is there any way to revert or undo git pull so that my source/repos will come to old state that was before doing git pull ? I want to do this because it merged some files which I didn't want to do so, but only merge other remaining files. So, I want to get those files back, is that possible?
You can do git reset --hard HEAD~1 to revert to the commit before the merge commit (assuming that's the latest). If you've made additional commits after the merge one, you would do git reset --hard HEAD~n where n is the number of commits after the merge + 1.

How to cancel a rebase after it has successfully completed : GIT

I need to come to the state before rebase.
The following command gives the error, which makes sense. My rebasing was successful.
git rebase --abort
No rebase in progress?
Any idea?
In the general case, if you completed your rebase, then your branch is now sitting on a new base of one or more commits, and you may have reworked some of the commits which were already on the branch, as you reapplied them.
One possible fix here would be to just reset your branch to the remote tracking branch:
git reset --hard origin/feature
Note that this option would only make sense if you have not made any new commits since you last pulled. Assuming this, the tracking branch would serve as a sort of backup of the branch before you did the unwanted rebase.

How to revert back to a fresh branch on git (removing all uncommitted changes)

How can I revert/delete all my changes that I did manually on local.
Example I have 2 branches
1) master branch
2) branch2
I checked out branch 2 and started to do some changes locally. I accidentally replaced a word for all the files. So now all my files are unsynced.
I want to start fresh again. (What ever I have in branch 2 that was committed and pushed) and remove all my local changes.
I've tried
git pull branch2
git reset --hard
git --hard branch2
git checkout .
But my recent changes are still existing in my local. Is there a command to revert this or do I have to clone the branch and start from there?
PS all my local changes were not committed at all.
Thank you
You could do a git stash to temporarily store the changes you made and don't want to commit. And then do a git stash pop later to get them back. If you never want to see those changes ever again, then you can overwrite your local changes with a
git reset --hard
git pull
You said you didn't commit files so there are probably untracked local files that need to be removed. I would run a git clean -f . That'll remove the untracked files. If you also need to remove untracked directories (folders) you can do a git clean -df
Hope that helps!
This will vanish all the changes done on local and pull down the last committed changes on your branch.
git reset .
git checkout .
git checkout branch2
git fetch && git reset --hard origin/branch2

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

committed without git pull, not pushed due to conflict

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.