showkey
showkey

Reputation: 338

How can restore deleted file and re-push into github?

Several days before, i deleted a file :

git log

Check the log info and get the id to restore

git checkout 424a74fba6fbf6ad53e59e7d579427b7acdfde file_name

The deleted file restored in my local workspace. I issue command to push after adding some new files, , and want to pull them all(make the restored file in the github also).

git add .
git commit -m 'restore deleted file'
git push https://github.com/xxxx/xxxx.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxxx/xxxx.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.

I git pull according to the notes, then push, but the restored file lost again. How can issue a new push and keep the restored file? Or say the restored file and other new added file push into github together without any error.

Upvotes: 0

Views: 31

Answers (1)

geeky01adarsh
geeky01adarsh

Reputation: 400

You may try to rebase your remote base with the local base by the following command:

git pull --rebase origin master 
git push origin master

or force pushing may help:

git push -f origin master

Upvotes: 1

Related Questions