Last active
November 16, 2016 15:24
-
-
Save codepedia/c5405ddfe7a4ce49f74a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns back what was changed after gitting pull locally. | |
git diff HEAD^^ HEAD nmae/of/thefile.rb | |
FYI , | |
# this will show what was last added your local "showing newly added changes" | |
git diff --color HEAD^ HEAD | |
# this will do the reverse .. it will show the commit prior to pulling from the remote. | |
git diff --color HEAD HEAD^ | |
======================================================== | |
gets the diff between between branch and master , and you can pass the name of the file as an arg. | |
[za]$ git diff --color-words master..somebranch^^ somescripts.rb | |
[za]$ git diff --color master^..origin/master # compare master before pulling from origin/master | |
OR | |
]$ git diff --color master..origin/master^ | |
# compare newly created branch with the master in which the branch was created from . | |
git diff name_of_branch remotes/origin/HEAD | |
======================================================== | |
⇓⇓⇓⇓⇓⇓⇓⇓⇓⇓⇓ | |
git log "$@" --pretty=format:'%T %h %s' | |
2108234324343432432432432423432423432434 4324349 Addmyapp first comment | |
2erwrdd3c0e6ea4aa6c37e835e d13d936 Add some comment | |
d15e56ewerwd620eb3cf3a6fdf12b89d f6af877 Add some morestuff | |
1578b58868d3af476ea6b00e4ea5c473a5c52c3b cc23989 changed the engine oil | |
erweeewrerererwererwer2da096cef340a48862c c04f506 not yet done. | |
============================================================================== | |
git push -all -u | |
pushes master /branches at once. | |
============================================================================== | |
had this | |
-sh-4.1$ git branch | |
master | |
* somebranch | |
and wasgetting | |
sh-4.1$ git push | |
! [rejected] master -> master (non-fast-forward) | |
error: failed to push some refs to 'git@github,,,,,' | |
fixed it like this…. | |
git checkout master | |
git pull | |
(merge happens in background) | |
git push | |
then | |
sh-4.1$ git checkout branchname | |
Switched to branch 'branchname | |
-sh-4.1$ git push | |
Counting objects: 3, done. | |
Compressing objects: 100% (3/3), done. | |
Writing objects: 100% (3/3), 633 bytes, done. | |
Total 3 (delta 0), reused 0 (delta 0) | |
remote: => Syncing Git... [OK] | |
da8sds1..c11sd master -> master | |
============================================================================== | |
rename a branch locally and remotetly . | |
git branch -m old_branch new_branch # Rename branch locally | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote | |
============================================================================== | |
# pull from a branch. | |
git pull origin other-branch | |
git log --author="<[email protected]" --oneline --shortstat | |
============================================================================== | |
git commit --amend -m "New commit message" | |
=============================================================================== | |
reverting to previous head : | |
git reflog | |
git reset --hard sdfdd0ea5 or HEAD^ or HEAD@{2} | |
=============================================================================== | |
# after git pull , take the commit hash and compare it woth local head^ to see the difference between the two. | |
git difftool HEAD^ 062f72413335508beea563f53be17156b5bd9ecc | |
========================================================================== | |
#Another way to compare the current master with the upstream master, is by doing a git fetch and then compare the | |
# fetched_head before mergeing the changes with the current head. | |
git fetch | |
git log -p HEAD..FETCH_HEAD | |
or | |
git diff --color master origin/master | |
=============================================================================== | |
fatal: git checkout: updating paths is incompatible with switching branches. | |
Did you intend to checkout 'origin/somebranch' which can not be resolved as commit? | |
solve it : | |
I believe this occurs when you are trying to checkout a remote branch that your local git repo is not aware of yet. Try: | |
git remote show origin | |
If the remote branch you want to checkout is under "New remote branches" and not "Tracked remote branches" then you need to fetch them first: | |
git remote update | |
git fetch | |
Now it should work: | |
# create local branch and pull remote into it .... | |
#Warning .. doing just git pull origin branc_name will cause the branch to merge with master. | |
git checkout -b local-name origin/remote-name | |
~ | |
~ | |
~ | |
[za$ git remote show origin | |
* remote origin | |
[za]$ git branch -vv | |
===========================OBJECTS==================================== | |
A single tree object contains one or more tree entries, each of which contains a SHA-1 pointer to a blob or subtree with its associated mode, type, and filename. For example, the most recent tree in a project may look something like this: | |
git cat-file -p master^{tree} | |
#use the army swiss knife git cat-file -p fdsfdf909dfs9dfsd9f0sdf to decipher the checksum "SHA" | |
git cat-file -p | |
------------------------------------- | |
Wanted to add two remotes so that i can push to / pull from ,... the way to do is like this | |
# if the remote is not created yet , do | |
za:vi_dir za$ git remote add origin [email protected]:z-a/vi_dir.git | |
za:vi_dir za$ git remote -v | |
origin [email protected]:z-a/vi_dir.git (fetch) | |
origin [email protected]:z-a/vi_dir.git (push) | |
# if it s created and you just want to link it , then do : | |
this will only allow you to push: | |
za]$ git remote set-url --add --push origin [email protected]:apps/some-repo.git | |
#without --push it will be set to push and pull. | |
za]$ git remote set-url --add origin [email protected]:apps/some-repo.git | |
and the best of all is to run the following command and add/delete remotes as desired. | |
za]$ git config -e | |
# one of the coolest commands ever... eg . git ls-files -s OR -c OR -d... check th manual page | |
za]$ git help ls-files | |
------------------------------------- | |
reverting a push can be easl=ily done if you are the last person who pushed . | |
https://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fixing-mistakes | |
za] git reflog | |
bf2a94r HEAD@{0}: blah blah | |
bf2a94r HEAD@{1}: The commit I want to go back to . | |
>> got the commit number , now reet head to the head{1} | |
]$ git reset --hard HEAD@{1} | |
>>another reflog will tell what was changed . | |
za] git reflog | |
bf2awef HEAD@{0}: HEAD@{1}: updating HEAD | |
>> git diff with two ".." | |
git diff 231062d..bf2a95e | |
------------------- | |
e]$ git var -l | |
SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/ \1/p') ; echo $SOB | |
# search entire reflist for a string. | |
za$ git rev-list --all | ( while read revision; do git grep -F 'liberty' $revision; done; ) | |
-------------------- | |
#check out remote branch without having to checkout from master "in case you master is bad" | |
git branch --set-upstream branchname origin/branchname | |
======================= | |
# On branch master | |
# Your branch is ahead of 'origin/master' by 30 commits. | |
solved with | |
git pull origin #but this will bring down everything from the upstream. | |
in a second time, i solved with | |
git reset HEAD^ --hard | |
# | |
git checkout somebranch | |
error: Untracked working tree file 'somefile.rb' would be overwritten by merge. | |
Fixed it by doing . | |
git fetch --all | |
-sh-4.1$ git reset --hard origin/somebranch | |
Checking out files: 100% (24/24), done. | |
git log --all --oneline --graph --decorate | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment