在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
grunt-git
Getting StartedIf you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: npm install grunt-git --save-dev Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: grunt.loadNpmTasks('grunt-git'); Upgrading from v0.2.xThe Universal optionsThe following options may be applied to any task options.verboseType: Console output from the git task will be piped to the output of the grunt script. Useful for debugging. options.cwdType: Change the current working directory before executing the git call. Useful for performing operations on repositories that are located in subdirectories.Note: When performing commands that provide files (e.g. gitcommit), it is also necessary to specify the Example:grunt.initConfig({ gitcommit: { your_target: { options: { cwd: "/path/to/repo" }, files: [ { src: ["fileone.txt", "filetwo.js"], expand: true, cwd: "/path/to/repo" } ] } },}) The "gitadd" taskAdd file contents to the index Optionsoptions.allType: Update the index not only where the working tree has a file matching but also where theindex already has an entry. This adds, modifies, and removes index entries to match the working tree. options.forceType: Allow adding otherwise ignored files. Usage Examplesgrunt.initConfig({ gitadd: { task: { options: { force: true }, files: { src: ['test.txt'] } } },}); The "gitcommit" taskCommits the working directory. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitcommit: { your_target: { options: { // Target-specific options go here. }, files: { // Specify the files you want to commit } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.messageType: The commit message. options.descriptionType: The commit description. options.allowEmptyType: When options.noVerifyType: When options.noStatusType: When Usage ExamplesCommit options:
grunt.initConfig({ gitcommit: { task: { options: { message: 'Testing', noVerify: true, noStatus: false }, files: { src: ['test.txt'] } } },}); The "gitrebase" taskRebases the current branch onto another branch Optionsoptions.branch (required)Type: options.theirsType: When true, use the git equivalent of svn's Usage Examplesgrunt.initConfig({ gitrebase: { task: { options: { branch: 'master' } } },}); The "gittag" taskCreates (or deletes) a git tag. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gittag: { your_target: { options: { // Target-specific options go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.tagType: The name of the tag. E.g.: options.messageType: The tag message (optional). options.removeType: Whether to delete the tag (optional). options.annotatedType: Whether to create an annotated tag (optional). options.forceType: Whether to force to create or update the tag (optional). Usage Examplesgrunt.initConfig({ gittag: { addtag: { options: { tag: '0.0.1', message: 'Testing' } }, deletetag: { options: { tag: '0.0.1', remove: true } } },}); The "gitcheckout" taskCreates a git branch using checkout -b, or checks out a given branch. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitcheckout: { your_target: { options: { // Target-specific options go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.branchType: The name of the branch. E.g.: options.createType: Whether the branch should be created (optional). options.forceType: Whether the checkout should be forced in the case of git errors (optional) options.overwriteType: Whether the branch should be overwritten, or created if it doesn't already exist (optional). NOTE: When enabled, this option overwrites the target branch with the current branch. Usage Examplesgrunt.initConfig({ gitcheckout: { task: { options: { branch: 'testing', create: true } } },}); The "gitstash" taskStash the changes in a dirty working directory away. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitstash: { your_target: { options: { // Target-specific options go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.commandType: The stash command to run. E.g.: options.stashType: The stash to apply. E.g.: options.stagedType: Whether the staged changes should be reapplied (optional). Usage Examplesgrunt.initConfig({ gittag: { stash: { options: { create: true } }, apply: { options: { command: 'apply', staged: true, stash: '0' } } },}); The "gitclone" taskClones a git repo. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitclone: { your_target: { options: { // Target-specific options go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.bareType: Run git clone with the options.branchType: Clone the repo with a specific branch checked out. (Cannot be used in conjunction with 'bare') options.depthType: Clone the repo with a limited revision history. (Such clones cannot be pushed from or pulled to.) options.repository (required)Type: The path to the repository you want to clone. options.directoryType: Clone the repo into a specific directory instead of the one git decides. options.recursiveType: Pass the --recursive flag to the git clone command. This is equivalent to running git submodule update --init --recursive immediately after the clone is finished. Usage Examplesgrunt.initConfig({ gitclone: { clone: { options: { repository: 'https://github.com/you/your-git-repo.git', branch: 'my-branch', directory: 'repo' } } },}); The "gitreset" taskCreates a git branch using checkout -b, or checks out a given branch. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitreset: { your_target: { options: { // Target-specific options go here. }, files: { src: // Target-specific files go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.modeType: The reset mode to run. E.g.: options.commitType: Which commit to reset to (optional). Usage Examplesgrunt.initConfig({ gitreset: { task: { options: { mode: 'hard', commit: 'HEAD~1' } } },}); The "gitrm" taskRemoves files from git's working tree and index. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitrm: { your_target: { options: { // Target-specific options go here. }, files: { src: // Target-specific files go here. } } },}) Each target defines a specific git task that can be run. The different available tasks are listed below. Optionsoptions.forceType: Will force a removal of the files listed in the configuration. options.recurseType: Will recurse into subdirectories if specified in the configuration. Usage Examplesgrunt.initConfig({ gitrm: { task: { options: { force: 'true' }, files: { src: ['dist/test.min.js'] } } },}); The "gitclean" taskRemove untracked files from the working tree. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitclean: { your_target: { options: { // Target-specific options go here. }, files: { src: // Target-specific paths go here (optional). } } },}) Optionsoptions.forceType: Force a run of the clean command (optional). options.dryType: Don't actually remove anything, just show what would be done (optional). options.quietType: Be quiet, only report errors, but not the files that are successfully removed (optional). options.excludeType: In addition to those found in .gitignore (per directory) and $GIT_DIR/info/exclude, also consider the given patterns to be in the set of the ignore rules in effect (optional). In case it's needed to provide multiple patterns one should use an array: grunt.initConfig({ gitclean: { your_target: { options: { exclude: ['.env', 'config.php'] }, ... } },}) options.onlyignorefilesType: Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files (optional). options.nonstandardType: Don't use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with this option. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build (optional). options.directoriesType: Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default (optional). The "gitpush" taskPushes to a remote. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitpush: { your_target: { options: { // Target-specific options go here. } } },}) Optionsoptions.remoteType: The remote where to push. E.g.: options.branchType: The remote branch to push to. E.g.: options.allType: Will add the options.tagsType: Will add the options.upstreamType: Will add the options.forceType: Will add the The "gitpull" taskPulls from a remote. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitpull: { your_target: { options: { } } },}) Optionsoptions.remoteType: The remote to pull from. The task will not fail if the origin is left unset and pull the default remote git origin. options.branchType: The branch to pull from. E.g.: The "gitfetch" taskDownload objects and refs from a repo. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitfetch: { your_target: { options: { all: true } } }}) Optionsoptions.repositoryType: The repository you want to fetch from. When no remote is specified, by default the origin remote will be used. options.allType: Adds the options.appendType: Adds the options.pruneType: Adds the options.notagsType: Adds the options.tagsType: Adds the The "gitrevParse" taskPick out and massage parameters. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitrevParse: { your_target: { options: { short: 7, treeIsh: 'master', prop: 'gitrevParse.your_target.result', callback: function(result) { grunt.gitrevParse.your_target.result = result; } } } }}) Optionsoptions.shortType: Adds the options.treeIshType: The tree or commit object to examine. options.abbrevRefType: Adds the options.propType: The grunt property in which to store the results. options.callbackType: A callback function that is called with the rev-parse results provided as the sole parameter. The "gitmerge" taskMerges another branch into the current branch. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitmerge: { your_target: { options: { // Target-specific options go here. } } },}) Optionsoptions.branchType: The branch to merge from. E.g.: options.ffOnlyType: Will add the options.noffType: Will add the options.nologType: Will add the options.squashType: Will add the options.editType: Will add the options.noEditType: Will add the options.messageType: Will add the options.commitType: Will add the options.noCommitType: Will add the options.strategyType: Will add the options.strategyOptionType: Will add the The "gitarchive" taskArchives a branch. OverviewIn your project's Gruntfile, add a section named grunt.initConfig({ gitarchive: { master: { options: { format: 'tar.gz', prefix: 'your-project-name/', treeIsh: 'master', output: '/tmp/your-project-name.tar.gz', path: ['README', 'LICENSE'] } } }}) Optionsoptions.treeIshType: |
请发表评论