git

git is a version

  1. command to add a modified file or directory

    git add filename-or-directry-name

  2. Command to add all modified file

    git add -u

  3. Command to commit

    git commit -s

  4. Command to checkout multiple modified file.

    git status | grep modified | sed 's/^.*modified: //' | xargs git checkout note: check space between modified: and //

  5. Command to remove white space and cleanfile in all modified file

    git status | grep modified | sed 's/^.*modified: //' | xargs ./cleanfile note: cleanfile is a script present in current folder.

  6. Command to push in specific brance with review

    git push origin HEAD:refs/for/dev1.0 note: origin means head(main) branch and dev1.0 is current brench where we want to push

  7. Command to checkout specific commit

    git checkout commit-number

  8. Command to create new branch

    git checkout -b new_branch_name

  9. To delete a git branch

    git branch -d branch_name

  10. create git patch from commit

    git format-patch -n note: where n is number of commit, each commit will generete a patch file

  11. Apply a git patch generated by git format-patch

    a) git apply --stat a_file.patch b) git apply --check a_file.patch c) git am --signoff < a_file.patch

  12. configure user information

    git config --global user.name "Your name" git config --global user.email "Your email id" git config --global branch.autosetuprebase always git config --global color.ui true git config --global color.status auto git config --global color.branch auto git config --global core.editor vim git config --global merge.tool vimdiff git config --list

  13. To clone git repositery first time use

    git clone https://github.com/user/Repo-name

  14. go inside project directry

  15. add new file a) create new file using your editor. b) use command git add filename c) to check status use command git status d) then use commit to update added file using command git commit -m "your comment" e) git pull f) git push g) git push origin master

  16. delate file a) git rm filename b) git commit -m "your comment" c) git pull d) git push

  17. to undo the delate file a)to find a deleted file and its commit: git log --diff-filter=D --summary # all deleted files ever git log --diff-filter=D --summary . # all deleted files in cwd git log --diff-filter=D --author=Batman --summary # all files deleted by Batman b)for undo git checkout ~1 c) and then reapeat step 4 with undo file name.

  18. to checkout only one file git checkout -- filename

  19. to push in a branch git push origin HEAD:refs/for/dev1.0

  20. to create patch or current changes git status > filename.patch

  21. to apply patch git apply filename.patch

  22. A git commit --amend


©2023-2024 rculock.com