دستورات مهم
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# show all branches $ git branch -a # rename branch $ git branch -m oldname newname # delete branch $ git branch -d name # clone specific branch $ git clone -b <branch> <remote_repo> # git clone -b developr origin/develop # stage all indexed files that has changed $ git add -u # --update # stage both modified and untracked files $ git add -A # --all $ git commit -m "message"-a # to update local branches which track remote branches $ git pull --all # set remote push branch # git push --set-upstream origin mirhossein/ref35 # create a new branch and apply stashed changes in the top of it $ git stash branch # view modifications between two branches $ git diff master..develop $ git diff origin/develop..develop # view changes of a specific file $ git diff -- filename $ git diff master..develop -- filename # the previous commit: HEAD^, HEAD~, HEAD^1 # Three commit before this commit: HEAD~3 or HEAD^^^ # if you just want to view what the file looked like in commit x, you can use git show $ git show a4r9593432:path/to/file.txt # to get the differences between the commit and the current HEAD $ git show a4r9593432 path/to/file.txt # you can quickly review the changes made to a file using the diff command: $ git diff <commit hash> <filename> # show merge conflicted files $ git diff --name-only --diff-filter=U # show file history $ git log -p filename # show merge conflicts $ git diff --check # show conflicted files $ git diff --name-only --diff-filter=U # search through all the commits, which should include all the branches $ git grep <regexp> $(git rev-list –all) # remove untracked files from the working directory $ git clean # -d to remove directories to # unstage pending changes, the changes will still remain on file system # you may need to use the --hard option if you have local modifications. $ git reset # unstage pending changes, and reset files to pre-commit state $ git reset --hard HEAD # to revert a specific file to that commit use the reset command $ git reset <commit hash> <filename> # revert files to specific commit # assuming the hash of the commit you want is c5f567 $ git checkout c5f567 -- file1/to/restore file2/to/restore # restore a deleted file $ git checkout c5f567 <filename> # apply changes of a branch without the commit history $ git merge --no-commit --squash branch |
تنظیم آدرس reposiory
1 2 3 4 |
$ git remote set-url origin https://git.com/USERNAME/REPOSITORY.git # or with ssh $ git remote set-url origin git@git.com:USERNAME/REPOSITORY.git $ git remote -v |
اتصال به گیت با ssh
1 2 3 4 5 6 7 8 9 |
# first set remote ssh url then # generate ssh key if you haven't any $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # add your SSH private key to the ssh-agent $ ssh-add ~/.ssh/id_rsa # now copy content of ~/.ssh/id_rsa.pub to you account $ xclip -sel clip < ~/.ssh/id_rsa.pub # and test connection $ ssh -T git@git.com |