Reputation: 11
So I messed up my code on my local but luckily I commit to Git daily.
I've gone to my Git repo, downloaded the last working version of my code (from .zip format) and now I want to replace my code on my local.
How do I continue git push
without resetting the number of commits?
Do I do a git pull
first?
Upvotes: 0
Views: 38
Reputation: 11
I have found another way of backtracking to a point in my application that was working before I mess up.
First, stash away any uncommitted changes otherwise Git will complain:
git stash
Then, simply check out an older branch that you know has the correct, working code. It could be the master branch, or some other branch like contact_form, etc. (replace previous_branch_name below with whichever branch you want to switch to):
git checkout previous_branch_name
Delete the branch with the broken code to keep things organized:
git branch -D broken_branch
Then checkout a new branch, and name it whatever is relevant:
git checkout -b new_branch_name
Now, you will be back to the point where the app was working before in a previous branch's state!
Upvotes: 0
Reputation: 11
I recreated the problem and I also found another solution to my problem that work:
After I downloaded my Git backup and unzipped it, in terminal I ran
git init
followed by
git remote add origin the-name-of-my-git-backup.git
before running git pull the-name-of-my-git-backup.git
After that, I was able to resume git add
, git commit
and finally git push
.
Definitely an experience!
Upvotes: 0
Reputation:
To reset your checked-out branch to look exactly like branch master
on remote origin
, do:
git remote update
followed by:
git reset --hard origin/master
If you also want to get rid of any build-generated/manually-created files, use a flavor of git clean (please refer docs):
git clean -fdx
Upvotes: 0
Reputation: 141946
If you downloaded a zip you don't have any .git
folder. You need to re-clone the project again and then place your changes on top of it.
do a second clone and use a diff tool like beyond compare to compare the 2 folders and copy changes form one folder to the second one and then commit those changes.
Upvotes: 1