Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
When you commit to git, then you push and get rejected:

$ git push
To my_repo:~/my_project.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to 'my_repo:~/my_project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

To prevent merging with your local and making your git history filthy, reset head to the latest commit (head~1):

$ git reset HEAD~1
Unstaged changes after reset:
M another_file_here.py
M some_file_here.py

Now git pull and the commit again and push. The world is cleaner now.

#git #reset_head #merge #repository
In normal git flow in case you have to checkout a file you would use:
git checkout -- your_file_name

In case you want to checkout multiple files you give other file names in front of checkout --. Sometimes there are bunch of modified files that you want to checkout all of them at once, so you need to go to the root of the project and:
git checkout -- .

It will checkout all files in your project.

You can also use:
git reset --hard

It will reset your working directory and replace all changes (including the index).

#git #checkout #reset #hard