I use Android Studio and I did by mistake a Git push force to my project. I want to undo the push force and revert back my local changes to my project, because my project is new and I did not commited any thing.
Can I revert all the latest changes which were before I did push force using Local history feature in Android Studio?
Can I see all local changes which I did before I clicked on push force using Local history feature. I wonder if all local changes will be saved in Local history even if I did force push?
Note: Now I dont have the project becuase its not in my own computer. Therefore I just wonder and asking here to fix the problem later.
Thanks for help
You can
look at git reflog to find the old commit you want to be at the head of, git reset --hard to it, and git push --force again;
Use git log to find the commits you don’t want, git revert them, and push normally; or
Find someone else with a clone that has the correct history and ask them to git push --force
The reflog shorthand ##{n} can be helpful here. N can be a number or even a date (see git help reflog and git help revisions).
Related
I wanted to go back and start from a certain commit so I did a hard reset and then I committed those changes now my log looks like in the picture. So what I want to do is completely replace those 2 old commits with the new 2 commits like those old 2 commits never happened. Is there a way to do this?
Your local looks good. You have to rewrite your remote repo.
git push origin --force
I have changes on devel branch. I checked out on master without commiting the changes. All the local changes got deleted in devel. How can I retrieve them?
Android Studio local history might help you, and see here Accidentally reverted to master, lost uncommitted changes, it really depends on your case.
I am not sure if it's possible to compare master branch (or any other) with the current feature branch like GIT does.
I want the Diff between two branches (master and feature branch) so that I can compare the diff before merging.I find Git UI less user friendly. As in AS I can traverse through code and change it right there.
I have found an option where I can compare any branch with my current local branch (that seem's like a solution to me but when I used it I got very confused).
Compare with current feature of AS compare two brach with specific selected commit.
While what I required is compare latest of both. (head of feature branch with head of master).Like we get in merge request of Git.
P.S- I thought of selecting all commit's to get the whole diff but it give a very different result something mix of all the diff's.
Want to get something like this.
I compare by right clicking my 'app' directory --> git --> compare with branch
This is how I check code before I merge it into master:
1.) Create and check out 'master' branch or one that has the same code as what's in master. (This can be done via the Terminal tab in Android Studio.)
git checkout master
OR
git checkout master_code_review_branch
2.) Run this command in the terminal to copy the commits from the branch you wish to compare (ex. ORIGIN/BRANCH_TO_MERGE) into the branch you've checked out. It will not commit.
git merge --no-commit --no-ff ORIGIN/BRANCH_TO_MERGE
3.) Now you can see all the individual changes in Android Studio by checking the "Version Control" tab or in the "commit" confirmation menu.
When done, you can "Abort Merge" in Android studio UI or via this terminal command:
git reset --merge --hard
More details here if you're interested:
https://medium.com/#mkutlev/pull-request-review-with-intellij-idea-or-android-studio-e60fbb3e3639
There doesn't appear a direct way. But there is a way if you look closely.
No need to make a new branch, if you can spot a branch which has
last commit on a previous time compared to the commit you want to
compare with.
If not, just make a local branch by title of your choice.
Use "Compare with Branch..."
All the commits between the selected branch head appear in the table. So spot your needed commit here.
Use the tabs titled Log or Files for comparing the revisions better.
I am new to Android Studio and have began developing a Navigation Drawer app.
After having made a mistake in a commit, I played around with the Version control's "Checkout Revision" and now I can no longer push my project onto Github due to a "Detached HEAD".
How can I fix this problem? My app runs perfectly fine in the emulator.
Thanks
you can go to VCS menu then Git, Branches, then in Git Branches dialog click on item below local branches then checkout branches and then accept your default branches.
it will connect your project to it's default branch and you can commit your project.
If you already made a lot of changes and want to commit and push online but out of sudden got this detached head issue, here are steps you can do for Git through Android Studio:
Go to VCS -> Git -> Branches...
Click the +New Branch, just put any temporary name.
Then commit your changes to the new branch (don't push yet, since it'll create new branch online).
Go to VCS -> Git -> Branches... again and now select the previous branch(local) with the detached head issue and click checkout branch.
Go to VCS -> Git -> Branches... again and now select the newly created branch(local) and select merge into current.
After success merge, double check if your code is the latest one. Now you can push the branch(previously got issue) without detached head issue. If you click commit at this point there'll be nothing to be committed since you have merged the latest changes. All you need to do is just push online. By this you prevent yourself from creating new branch online just to fix this issue.
For cleaning purpose, once you managed to push the branch online, just select again the newly created branch(local) and click delete branch.
When you are in a 'detached head state' in Git, it means you are currently viewing history according to a past commit that is not on a branch. A few things need to happen based on what your goal is.
If you want to continue your code in the currently checked out version? If so, you should check back out to the most recently made commit and then un-do history with git revert or git reset, whichever makes more sense for you.
If you want to just go back to your most recent commit and continue to work as normal, git checkout <newest SHA> will work totally fine.
To get rid from Detached Head you need to know why this problem is arrived. Its Showing Detached Head because you merge your project several times(or atlas twice) by just committing your project locally. What you need to do is that by every time you merge your project just commit it locally as well as to server branch too.
This will resolve your problem as it does mine.
The easiest quick solution is just to create new branch and push your current version there.
However, this solution is not the right one.
I created a branch and copy a commit to this one with command
git cherry-pick <commit number>
I have two branches, the development and the master.
Code in master branch can't have Log calls, comments, etc . Everything else is the same.
So when I merged to the master before commit I deleted everything I didn't want.
I continued developing on development branch and now I want to merge and commit the changes but I guess that will add again what I have previous deleted.
Is there a way to commit only the changes from the development branch or a workflow/solution for this problem ?
I'm using mercurial but I guess someone who is facing the same problem with git can help.
I'm new with mercurial and don't know much about git.
Thank you
Ideally you need to find a different method for tracking/sharing such items but if that is impossible then you could possibly use python hooks to filter them out of any commits to your master branch.
See this chapter of the hgbook for some discussion of some of the possibilities.