Advertisement
saratbhaswanth

Git Useful Commands

Jan 12th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | None | 0 0
  1. I recently started hosting my repos on my own server and found this handy way of looking at all the files from the repo without cloning (assuming you used the -bare option which doesn't show the files but has other benefits).
  2.  
  3. git log --pretty=format: --name-only --diff-filter=A | sort -
  4.  
  5. that's on the actual server, but you could call it from your local machine by ssh'ing to the server by:
  6.  
  7. ssh user@host "your git command here"
  8.  
  9. TO View Log:
  10. git log
  11. git log --name-status or git log --name-only or git log --stat
  12.  
  13. If you want to get the file names only without the rest of the commit message you can use:
  14. git log --name-only --pretty=format: <branch name>
  15.  
  16. This can then be extended to use the various options that contain the file name:
  17. git log --name-status --pretty=format: <branch name>
  18. git log --stat --pretty=format: <branch name>
  19.  
  20. git diff --stat HEAD^! shows changed files and added/removed line counts for the last commit (HEAD).
  21.  
  22. Show revision Number:
  23. git rev-list HEAD | wc -l
  24.  
  25. Ignore a file from tracking:
  26. git update-index --assume-unchanged <file>
  27.  
  28.  
  29.  
  30. To remove a file that you have added but not committed, use a command like this:
  31.  
  32. git rm --cached file.to.remove
  33.  
  34. This will remove the file from the index, but not touch the file on disk.
  35.  
  36. To remove a file (or files) from the most recent commit, use the above git rm --cached command followed by git commit --amend.
  37.  
  38. git reset --hard <commit-hash>
  39.  
  40. git rm -r --cached .
  41. git add .
  42. git commit -m "fixed untracked files"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement