Monday, April 18, 2016

[Github] How to return the previous commit after pusing commits.

Situation: create files on the local computer -> commit -> push it to the git (server)

If you'd like to delete files/folders on the github server,
you could delete files/folders on your local computer and then push the commit.

Delete files on the local computer -> commit -> push it on the git (server)

However the commit remains on the log (git log) as followings:
==============================================
commit XXX
Author: AAA
Date: BBB
   comment: File deletion
 
commit XXX
Author: AAA
Date: BBB
   comment: File upload
 
commit XXX
Author: CCC
Date: YYMMDD
   comment: I'd like to return to here!!
...
==============================================

If you also want to delete the commit, you could UNDO the process as follows.

1. git reset HEAD^
: Return to the previous commit.

(or git reset HEAD~2: return to the past second commit)

2. git push origin +master
: Push the pevious commit ignoring warning for data loss. (put a "+")



* If you push like as 'git push origin master', you would get the following error message:
-> It reject the push because it could cause data loss.
================================================================
To https://github.com/~~~.git
![rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/~.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

================================================================

 
* 참고한 한국어 설명 페이지
http://whiteship.me/?p=13516

No comments:

Post a Comment