Closed choongzhanhong closed 1 year ago
When running git log
locally it will show the history of all commits, could you paste the recent commits here so we know how your local history is like? Also could you paste the output of git status
as well?
running git log
I have a log of a commit I made:
$ git log
commit 1ee7646a757d98ec4302d3d39b000e64d849d87b (HEAD -> master)
Author: choongzhanhong <choongorilla@gmail.com>
Date: Sun Jan 15 18:37:35 2023 +0800
.gitignore: add *.class
Duke.java: add level-0 greet and exit message
before that, it is
commit 3b83789e9ed75b9498c05ee150c073f6492ec6ff
Author: Sean Leong <70213029+seanleong339@users.noreply.github.com>
Date: Thu Dec 29 13:56:26 2022 +0800
.gitignore: Fix ACTUAL.txt -> ACTUAL.TXT (#73)
and so on.
git status
shows:
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
Alright, from the output of git status
, your local branch has diverged from the remote (GitHub) branch. Your tree currently looks like this
old commits ─── previous commit ─── current commit (remote)
│
└──────────── current commit (local)
I also went to see your repository; your remote repository latest commit hash is 1f347c886abfbee97a1037d425de8f57b583054e
while your local repository latest commit hash is 1ee7646a757d98ec4302d3d39b000e64d849d87b
, confirming the above.
Now what to do? Normally people would probably merge the upstream to their local repo. But in this case, I don't think a merge is necessary (we haven't even studied about it yet). Instead, you probably want to force push/pull to discard one version and keep the other.
To discard the remote version (your remote commit will be gone), use git push --force
.
To discard the local version (your local commit will be gone), use git reset --hard origin/master
.
After these commands, the local repo will be synced to the remote repo, and you can then git push
or git pull
normally.
Please note that --force
and --hard
are dangerous and generally discouraged. Especially git push --force
, don’t use it for team (>1 person) projects. However, they can be used for cases like the one described here. Please remember to read their documentation as well.
Thank you! I have force pushed the commit from my local end. I'm not sure what caused the discrepancy, but for those who are using Sourcetree like me, there is a button on top-right to input terminal commands simply labeled terminal.
I just used git push --force
and it was successful.
Hi, I am trying to commit my level-0 change for iP, however I am receiving the following problems when pushing and pulling. Does anyone know what I can do in this situation? I Googled but don't quite know how to apply the solutions online.
Pull:
and Push error message: