Skip to content

Instantly share code, notes, and snippets.

@kalaiselvan369
Last active November 26, 2018 05:49
Show Gist options
  • Save kalaiselvan369/21daf1ec8254824fd356dff166320c62 to your computer and use it in GitHub Desktop.
Save kalaiselvan369/21daf1ec8254824fd356dff166320c62 to your computer and use it in GitHub Desktop.
Git commands
echo "# fresco-image-library-samples" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/glidodroid/fresco-image-library-samples.git
git push -u origin master
*** Create patch for last commit ***
git show HEAD > some-patch0001.patch
some-patch0001 == filename
or
git format-patch -1 HEAD
-------------------------------------------------------------------------------
*** Applying the patch
git apply --stat fixemptyposter.patch
This will show commits which is present in patch file
Patch also provide a way to test code before applying
git apply --check fixemptyposter.patch
*** Apply patch on branch
git am --signoff < fixemptyposter.patch
Above command add all patch commit to current branch
--------------------------------------------------------------------------------
*** Create a patch from diff (only modified files before git add)
git diff > mypatch.patch
---------------------------------------------------------------------------------
*** Create a patch for files which are added (after adding files using git add )
git diff --cached > mypatch.patch
----------------------------------------------------------------------------------
*** Apply patch
git apply mypatch.patch
---------------------------------------------------------------------------------
*** Create patch with commit id
git format-patch -1 <commit_id/sha>
----------------------------------------------------------------------------------
*** .gitignorefiles
The problem is that .gitignore ignores just files that weren't tracked before (by git add).
Run git rm --cached name_of_file and your file will be ignored again (in case it's mentioned in .gitignore)
caution : it will delete file from git repo.
----------------------------------------------------------------------------------------------------------------
*** change remote origin
git remote set-url origin (url_link)
----------------------------------------------------------------------------------------------------------------
*** fetching from origin****
git fetch origin
git checkout <branch> (remote/dev_2)
commit the changes and copy the commit id
git branch <branch name> <commit id> (will create new branch with above commit for pushing)
----------------------------------------------------------------------------------------------------------------
*** reverting several commits and moving to particular commit locally*****
git reset --hard <commit-id>
commit-id: commit which you want to move to.
-----------------------------------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment