Whenever you do git pull and you find some files modified locally as part of build and want to overwrite it with the contents in the git repository.<\/p>\n\n\n\n
git checkout HEAD^ file\/to\/overwrite
git pull<\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n\nTo checkout a new git branch and to create a new git branch and checkout<\/p>\n\n\n\n
git checkout <branch><\/p>
git checkout -b <branch> <\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n
\n\n\nTo delete a remote branch and local branch\n\n<\/p>\n\n\n\n
git push –delete origin bugfix\/
git branch -d bugfix\/<\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n\nTo copy a directory without its history and add as a new folder in git<\/p>\n\n\n\n
cp -R old_dir new_dir <\/code><\/p>
git add new_dir <\/code><\/p>
git commit -m \"first revision of new_dir's copied files\"<\/code> <\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n\nCreating a diff file<\/p>\n\n\n\n
git diff > 1.patch<\/p><\/blockquote>\n\n\n\n
Applying a git generated patch file<\/p>\n\n\n\n
git apply 1.patch<\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n
\nSaving your changes while checking out a branch<\/p>\n\n\n\n
git stash save<\/p>\n\n\n\n
if you have to save again<\/p>\n\n\n\n
git stash save<\/p>\n\n\n\n
stash@{1} – older changes…newest will become stash{0}<\/p>\n\n\n\n
git stash list – lists all stash<\/p>\n\n\n\n
git stash drop<\/p>\n\n\n\n
stash@{0} dropped. stash@{1} will become stash@{0}<\/p>\n\n\n\n
git stash apply stash@{2} – to apply changelist in stash{2}<\/p>\n\n\n\n
git stash drop stash@{2} – to drop the changelist in stash{2}<\/p>\n<\/div><\/div>\n\n\n\n
git stash pop - To get everything back\ngit checkout -b newbranch\ngit stash pop\n\n\ngit stash pop - Restore back to the saved state, but it deletes the stash from the temporary storage.\ngit stash apply - Restore back to the saved state and leaves the stash list for possible later reuse. Need to use below command to drop them.\ngit stash drop\n\ngit stash apply 1 is equal to git stash@{1} apply<\/code><\/pre>\n\n\n\nTo rename a git local branch<\/strong><\/p>\n\n\n\n
\nUse -m option to rename a branch. Here I forgot to add bugfix\/ prefix int he branch name. So -m command helped me to add it.\ngit checkout bugfix-branch\ngit branch -m bugfix\/bugfix-branch\n<\/code><\/pre>\n<\/div><\/div>\n\n\n\n\n\nTo cherry pick a pull request<\/strong><\/p>\n\n\n\n
Create a new branch form the origin branch where you want to add the fix.<\/p>\n\n\n\n
git branch cherry-branch origin\/master<\/p>\n\n\n\n
switch to the new branch<\/p>\n\n\n\n
git checkout cherry-branch<\/p>\n\n\n\n
Cheery pick the commit using commit id.<\/p>\n\n\n\n
Use git log to find the commit id.<\/p>\n\n\n\n
git cherry-pick COMMIT-ID<\/p>\n\n\n\n
Push the new branch to your fork<\/p>\n\n\n\n
git push origin cherry-branch<\/p>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n
\n
- References<\/strong><\/li>
- http:\/\/blog.asquareb.com\/blog\/2014\/06\/19\/making-a-git-pull-request-for-specific-commits\/<\/li>
- <\/li><\/ul>\n<\/div><\/div>\n\n\n\n
To Backport changes<\/strong><\/p>\n\n\n\n
To fetch all upstream changes
git fetch –all<\/p><\/blockquote>\n\n\n\ncreate the cherrypick branch from the branch intended to check-in<\/p>\n\n\n\n
git branch my_cherrypick_branch rel\/release_branch_to_checkin<\/pre>\n\n\n\ncheckout temporary cherry pick branch<\/p>\n\n\n\n
git checkout my_cherrypick_branch<\/code><\/pre>\n\n\n\ncherry pick the commit<\/p>\n\n\n\n
git cherry-pick dc4264056167c7ef9d496b276e9f2699d1b91106<\/code><\/pre>\n\n\n\npush the cherry pick branch to upstream.<\/p>\n\n\n\n
git push –set-upstream origin my_cherrypick_branch<\/p>\n\n\n\n
Now create the pull requests.<\/p>\n\n\n\n
to download again the artifact<\/h2>\n\n\n\n
\n\ngit lfs uninstall<\/pre>\n<\/div><\/div>\n\n\n\n\n\ngit pull<\/p><\/blockquote>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n
git lfs install<\/p><\/blockquote>\n\n\n\n
git lfs checkout<\/p><\/blockquote>\n<\/div><\/div>\n\n\n\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
Some commonly used git commands and problems occur in day to day life resolved.<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[1522],"class_list":["post-2064","post","type-post","status-publish","format-standard","hentry","category-tips","tag-git"],"_links":{"self":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2064"}],"version-history":[{"count":13,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2064\/revisions"}],"predecessor-version":[{"id":2309,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2064\/revisions\/2309"}],"wp:attachment":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2064"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}