diff --git a/.doxie.render.js b/.doxie.render.js new file mode 100644 index 0000000..ad9ac8b --- /dev/null +++ b/.doxie.render.js @@ -0,0 +1,19 @@ +function escapeStr(str) { + return str + .replace(/\"/g, '\\"') + .replace(/\n/g, '\\n'); +} + +var render = function(data) { + var data = data.data; + + return [ + '## ' + data.title, + '```sh', + data.tip, + '```', + '\n' + ].join('\n'); +}; + +module.exports = render; diff --git a/.doxie.render.toc.js b/.doxie.render.toc.js new file mode 100644 index 0000000..a5cd205 --- /dev/null +++ b/.doxie.render.toc.js @@ -0,0 +1,12 @@ +var tips = require('./tips.json'); + +var render = function(data) { + var data = data.data; + + var out = '* [' + data.title + '](https://github.com/git-tips/tips#' + data.title + ')\n'; + + if (tips[tips.length -1].title === data.title) out = out + '\n'; + return out; +}; + +module.exports = render; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93f1361 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/README.md b/README.md index d203f4e..0d37b4d 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,65 @@ -## Overwrite pull + + +* [Overwrite pull](https://github.com/git-tips/tips#Overwrite pull) +* [List of all the files changed in a commit](https://github.com/git-tips/tips#List of all the files changed in a commit) +* [Git reset first commit](https://github.com/git-tips/tips#Git reset first commit) +* [List all the conflicted files](https://github.com/git-tips/tips#List all the conflicted files) +* [List all branches that are already merged into master](https://github.com/git-tips/tips#List all branches that are already merged into master) +* [Quickly switch to the previous branch](https://github.com/git-tips/tips#Quickly switch to the previous branch) +* [Remove branches that have already been merged with master](https://github.com/git-tips/tips#Remove branches that have already been merged with master) +* [List all branches and their upstreams, as well as last commit on branch](https://github.com/git-tips/tips#List all branches and their upstreams, as well as last commit on branch) +* [Track upstream branch](https://github.com/git-tips/tips#Track upstream branch) + + + + + + +## Overwrite pull ```sh -git fetch --all -git reset --hard origin/master +git fetch --all && git reset --hard origin/master ``` ## List of all the files changed in a commit - ```sh git ls-tree --name-only -r ``` ## Git reset first commit - ```sh git update-ref -d HEAD ``` ## List all the conflicted files - ```sh git diff --name-only --diff-filter=U ``` ## List all branches that are already merged into master - ```sh -git checkout master -git branch --merged +git checkout master && git branch --merged ``` ## Quickly switch to the previous branch - ```sh git checkout - ``` -# Remove branches that have already been merged with master +## Remove branches that have already been merged with master ```sh -git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d +git branch --merged | grep -v '\*' | xargs -n 1 git branch -d ``` ## List all branches and their upstreams, as well as last commit on branch - ```sh git branch -vv ``` ## Track upstream branch - ```sh git branch -u origin/mybranch ``` + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..158ea8a --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "tips", + "version": "1.0.0", + "description": "collection of git tips", + "main": "index.js", + "private": "true", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "precommit": "npm run generate && git add README.md", + "update-readme": "echo 'Updating the readme…'; doxie --render < ./tips.json --inject into README.md && echo '…done!'", + "update-toc": "echo 'Updating the table of contents…'; doxie --render .doxie.render.toc.js < ./tips.json --inject into README.md as toc && echo '…done!'", + "generate": "npm run update-readme; npm run update-toc" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm-tips/tips.git" + }, + "keywords": [ + "npm", + "tips" + ], + "contributors": [ + "hemanth" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/git-tips/tips/issues" + }, + "homepage": "https://github.com/git-tips/tips#readme", + "devDependencies": { + "doxie": "^0.2.2", + "doxie.inject": "^0.1.1", + "doxie.output": "^0.3.0", + "doxie.render": "^0.3.0", + "husky": "^0.8.1" + } +} diff --git a/tips.json b/tips.json new file mode 100644 index 0000000..f1a77f9 --- /dev/null +++ b/tips.json @@ -0,0 +1,38 @@ +[ + { + "title": "Overwrite pull", + "tip": "git fetch --all && git reset --hard origin/master" + }, + { + "title": "List of all the files changed in a commit", + "tip": "git ls-tree --name-only -r " + }, + { + "title": "Git reset first commit", + "tip": "git update-ref -d HEAD" + }, + { + "title": "List all the conflicted files", + "tip": "git diff --name-only --diff-filter=U" + }, + { + "title": "List all branches that are already merged into master", + "tip": "git checkout master && git branch --merged" + }, + { + "title": "Quickly switch to the previous branch", + "tip": "git checkout -" + }, + { + "title": "Remove branches that have already been merged with master", + "tip": "git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" + }, + { + "title": "List all branches and their upstreams, as well as last commit on branch", + "tip": "git branch -vv" + }, + { + "title": "Track upstream branch", + "tip": "git branch -u origin/mybranch" + } +]