git
git is a version
-
command to add a modified file or directory
git add filename-or-directry-name
-
Command to add all modified file
git add -u
-
Command to commit
git commit -s
-
Command to checkout multiple modified file.
git status | grep modified | sed 's/^.*modified: //' | xargs git checkout note: check space between modified: and //
-
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.
-
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
-
Command to checkout specific commit
git checkout commit-number
-
Command to create new branch
git checkout -b new_branch_name
-
To delete a git branch
git branch -d branch_name
-
create git patch from commit
git format-patch -n note: where n is number of commit, each commit will generete a patch file
-
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
-
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
-
To clone git repositery first time use
git clone https://github.com/user/Repo-name
-
go inside project directry
-
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
-
delate file a) git rm filename b) git commit -m "your comment" c) git pull d) git push
-
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. -
to checkout only one file git checkout -- filename
-
to push in a branch git push origin HEAD:refs/for/dev1.0
-
to create patch or current changes git status > filename.patch
-
to apply patch git apply filename.patch
-
A git commit --amend
©2023-2024 rculock.com