hope you are having a good day.
I want to know a small thing about pull/push in git repo.
Below is the representation of my code/project.
Blue: This is my code which is worked on and without commit i pulled the red code from git.
Red: This is the older version of blue code.
Yellow: this is the code which i have now
So i have worked on blue code but without commit or push i pulled red code, so it over writes my blue updated code and merged as yellow code. So now i want to get back my blue code, is it possible? i searched in my project folder but i cant find it. i search on my git branch code too but it wasn't there too.
Thanks for the read, if you know how to revert that pull request it will save my couple of hours. Thanks again
And by the way this is an android project and code is in bitbucket.
[UPDATE] - Solved-
Thanks for the response. I got my blue code back using Android Studio Local History tool. Reverted all the changes that i have made.
Try git lola9 (if you've set up the alias, or whatever way you prefer to view your commit history), and you should see the commits you pulled. Alternatively, the console output of the git pull should also include the commits you pulled.
Once you have that, what I would do is:
Note the number of commits you want to git rid of
git stash your changes,
git reset head~n, where n is the number of commits we figured out earlier. This will 'un-commit' the changes you pulled
git co . & git reset as needed to 'lose' all those now un-commit-ed changes that you've pulled down
git stash apply to retrieve your changes (rather than pop in case somethings gone wrong, you don't want to dirty your changes)
Related
Hi i'm here to asking you, how to push my commit/chage(s) when i have another commit and i forgot to pull the commit from github.
This is the chronology: when i'm no have another work, i decide to make own project and i use git to be my vcs, and then i make my project to be repository.
A few day's later, i decide to remoting my github.
Everything is alright until the problem come. In one day, i'm edit my README.md and save the change, in git same to but a different is i updating my source code and save the change. After that i'm push my commit and this is happent.
Screen shoted the problem
But in here, i'm not realize i'm forgot to pull a commit from github until i'm realized that.
So please help me! I stuck in this condition! Please!
And i'm sorry if my English is bad
So, basically your solution might be to pull the changes from GitHub (that is, if I understand correctly you have did some changes to you remote Github - updated your README.md - not from your local - now you want that change to be reflected in your local and you need to push your new changes in the local to the remote).
The best solution would be to first add all your changes to staging and then committing by doing:
git add .
git commit -m "Your commit message (One-liner of your change)"
and then do a rebase as follows:
git pull --rebase
Rebasing will pull the changes from the remote, and re-apply your local changes on top of it, thus your local repo is now in sync with the remote repo (they are essentially in the same state). Now you can do the push:
git push <REMOTENAME> <BRANCHNAME>
I commit changes to git from Android Studio, after that I have made some changes in my project that gives me errors, and now I want to get back that commited version that has no errors.
How can I do that?
To undo your latest changes and reset to the most recent commit:
Go to VCS -> Git -> Reset HEAD..
Change Reset type to hard to remove those changes.
It will look like this. You can validate the reset before you do it if you want.
What happens if you click Validate?
A screen will pop up that shows the changes that were made in the commit you are about to reset to. You can view diffs per file that show what the commit changed in that file. It's more or less equal to what $ git show in a terminal would do.
Contrary to what I assumed before, it does not show what files will be affected when you perform the reset.
Just get your commit id using git log. Then you can use (with 0d1d7fc32 for example):
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
or if you don't want to save your changes (hard reset):
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32
If you want to go back to the last commit (without saving changes), then no need to get the id, go for:
git reset --hard HEAD
From this post
git reset --soft "HEAD^"
this will remove the latest commit.
According to this great article on jetbrains webiste here:
Reset a branch to a specific commit
If you notice an error in a set of recent commits and want to redo that part, you can roll back your repository to a specific state. This is done by resetting the current branch HEAD to a specified commit (and optionally resetting the index and working tree if you prefer not to reflect the undo in the history).
Open the Version Control tool window Alt+9 and switch to the Log tab.
Select the commit that you want to move HEAD onto and select Reset
Current Branch to Here from the context menu.
In the Git Reset dialog that opens, select how you want your working
tree and the index to be updated and click Reset:
Soft: all changes
from commits that were made after the selected commit will be staged
(that means they will be moved to the Local Changes view so that you
can review them and commit later if necessary).
Mixed: changes made after the selected commit will be preserved but will not be staged for commit.
Hard: all changes made after the selected commit will be discarded (both staged and committed).
Keep: committed changes made after the selected commit will be discarded, but local changes will be kept intact.
Suppose you want to commit project changes. When you want to commit files Android Studio will show you which files have been changed. See them and you can convert every file you want to last commit.
A very common thing that I tend to do is when I need to update a graphic or something in the drawable-nodpi folder, or any other folder for that matter, Android Studio doesn't detect the change so of course when I try to "PUSH" to GitHub it doesn't actually push and just tosses me the "No Changes Detected" message.
Is there a way to push anyways? Just to force a commit on specific files that I want to push because I know for a FACT there was a change and I need it submitted?
Lately I been having to delete it first from within Android Studio, then save the file, then add it to GIT then try a commit, but even this works only 70% of the time and is very annoying.
Perfect Example.... I have a splashimage.png in the drawable folder, I am in Photoshop and I change something then do an override to the splashimage.png with my change, but of course Android Studio doesn't see this as a change so I can't Commit this file to Git or anything.
Are you using external editors like photoshop when editing files? If so, press refresh in Android Studio to make it detect changes in file system. Then it says something has changed and suggest you to commit. Of course you can use command line to add changes anyway and commit without even using Android Studio.
Apparently the item I was looking for was the Synchronize. I just go to the file and Right Click > Synchronize and it then does a check against the last one manually and see's if it was different. Kind of a Refresh like Kuitsi had stated, but its called Synchronize. Also some reason I can't get it to work by just clicking Synchronize next to the SAVE icon at the top under File menu. Not sure why.
Whats your git status after you copy the file? Do you commit the changes, before pushing?
Have the same problem. Resolved.
The multi-root project used to work just fine for years, detecting changes in sub gits, properly pushing/pulling per sub, but not anymore. After some playing with a broken merge, it has stopped working. And that's not a local git repo issue. Cloned it from scratch - same issue. Changes (doesn't matter internal or external) are not detected by the Studio VCS facility, though git from console shows changes, View/Recent Changes shows them, Local Changes tab doesn't show any (single Default changelist).
It looks like something has happened with the VCS roots detection or related settings. Fixed with Preferences/version Control adding missing roots manually. I wish there is an option to rescan a folder or to delete some settings file and have the studio detecting these roots again.
Im using the repo tool to sync android source.
I have two questions about this;
When I change something in the source and sync later on but want to keep the changes, what is the correct way to do this? (im now doing git add ., git commit and later on merge if necessary) But this seems not to be the right way.
Can I reset the entire repo (all git dirs) to remove all commits but still keep all my changed files? (because they are all polluted with commits now)
Thanks.
As Far As I know repo does this for you. Once its done with sync it rebase you chanegs on TOP of that.
Or else you can try
git pull --rebase
So I'm not sure if this is possible but I'm hoping it is. Basically, we just moved to SVN from Sourcesafe (I know a lot of you almost threw up in your mouth just now ;)) and I'm setting up eclipse to work with it. I installed Subversive and have a repo set up with my project. Just FYI, I'm working on an Android project written in Java. Here's what I want:
As I'm working on each Java file making changes, I want to write the SVN Commit Messages right their in code just as I add javadoc comments. This is because I have to change a ton of files before I commit and I want to remember each thing I changed (client requirement). But I don't want to have to remember all of that (especially as I'm deleting a lot of code) and them add the comments when I commit all my changes from all my files. Ideally, I simply add some tag and then the commit message that SVN understands and as I commit the file, I don't have to manually add the comments but it gets done automatically based on the commit messages tagged in my source file?
As an example, say I deleted a function foo in footest.java, I would simply type in the following in footest.java:
// __ (hopefully some tag here) deleted foo
Now when footest.java is commmitted, I don't have to type anything, the commit message 'deleted foo' gets added to it.
Finally, ideally, this is done automatically per revision. That is, once I make another change in footest.java, say, added function newfoo(), I could tag it like before with comment "added newfoo()" and when I commit only "added newfoo" comment gets put on the revision and not the one for the previous version "deleted foo".
Is this possible? Any issue anyone sees here?
Thanks,
-Vivek
Generally speaking, mixing your commit messages & your code is discouraged.
Subversion (or any client I'm aware of) has nothing of the kind built in, because it would require knowledge of the code itself and your custom markup.
You would need to write a wrapper around svn commit (or your client's equivalent) to process your files.
But have you considered that to do this right, you'd also have to remove those comments from your code once you've committed the changes? Now you're into your wrapper script messing with your code - and a bug there could break your code, either introducing subtle, hard-to-find bugs or rendering it impossible to compile.
Why not just keep a text file on your desktop with your notes? Or make smaller self-contained commits instead of delaying until the point where you've forgotten why you made some of the changes?