git add Nothing specified, nothing added - cypress-component-test-runner

hint: Maybe you wanted to say 'git add .'?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"
add in repository GitHub via GitBash

Related

Skip travis build if an unimportant file changed

I use continuous integration with Travis to run my unit tests on every commit. However, sometimes all I want to do is edit the README. Is there a way to skip Travis builds if all the changes are restricted to a whitelisted set of files?
There's no way to directly make Travis dynamically determine, based only on the type of file that has been changed, if it should run a build.
However, Travis will ignore any commit with [ci skip] or [skip ci] in the commit message.
Perhaps you could use a git hook (say prepare-commit-msg or similar) to append [ci-skip] to the commit message when only .md files have been modified.
In the git hook, you could detect this scenario with a command like git diff --exit-code --name-only -- . ':(exclude)*.md'.
In action:
$ git diff --name-only
README.md
$ git diff --exit-code --name-only -- . ':(exclude)*.md'
$ echo $?
0
If any non *.md files have been changed, the command will return 1, otherwise 0.

How do I push to git from Jenkins?

The following code is an "Execute Shell" build step in Jenkins. The job pulls from a repo which contains a file ranger-policies/policies.json. What I'd like to do is update that file (with a curl command, in this case) and then commit the change to source control and update the remote repo. The job successfully pulls from the remote repo in the "Source Code Management" section of the job configuration page over SSH using SSH keys. However, when the job gets to the "git push origin master" line in the "Execute Shell" step, I get a Permission denied (publickey) error, as if those same SSH keys which allowed me to successfully pull the repo are not available in the "Execute Shell" step when I want to push.
curl -X GET --header "text/json" -H "Content-Type: text/json" -u user:pass "http://my-url.com/exportJson" > ranger-policies/policies.json
git add ranger-policies/policies.json
git commit -m "udpate policies.json with latest ranger policies `echo "$(date +'%Y-%m-%d')"`"
git push origin master
I ended up figuring out how to make it work. The solution involves using the SSH Agent plugin. Here's a step-by-step that describes how I did it, hopefully it helps someone else:
First, create a new pipeline job.
Then, as hinted at in this post from Jenkins' documentation, go to the home screen for your new pipeline job, and click on "Pipeline Syntax." Choose "git: Git" as the "Sample Step, and enter the git repo you want to push to in the "Repository URL" field. Then choose the corresponding valid SSH keys for that repo from the "Credentials dropdown." Everything should look like this:
Grab the value of "credentialsId", highlighted with red in the above screenshot. You'll need it later.
Install the "Workspace Cleanup Plugin" (https://wiki.jenkins.io/display/JENKINS/Workspace+Cleanup+Plugin, optional) and the "SSH Agent Plugin" (https://jenkins.io/doc/pipeline/steps/ssh-agent/, not optional, required for this process to work).
Now go back to your new pipeline job and hit "Configure," which will take you to the screen where you define the job. Drop the following code into the "Pipeline" section ("Definition" should be set to "Pipeline script"): https://gist.github.com/ScottNeaves/5cdce294296437043b24f0f3f0a8f1d8
Drop your "credentialsId" into the appropriate places in the above Jenkinsfile, and fix up the repo names to target the repo you want, and you should be good to go.
Relevant documentation:
https://jenkins.io/doc/pipeline/examples/#push-git-repo
https://gist.github.com/blaisep/eb8aa720b06eff4f095e4b64326961b5#file-jenkins-pipeline-git-cred-md
https://issues.jenkins-ci.org/browse/JENKINS-28335?focusedCommentId=269000&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-269000
As per this gist, you need to set the remote origin url as per:
git remote set-url origin git#github.com:username/your-repository.git

Correct way of committing changes to master branch on Github

So I am very new to Github. Please forgive me if i am asking a stupid question. So first did some reading on Github and tried to understand the philosophy about it. So i am working on my first ruby on rails app (very excited) I generated my new app and made my first commit by pushing the empty app to Github. So now i have a master branch.
Then i created a couple of models and added some fields to the tables i made. Now i would like to push this change on Github . What do i do and how? I KNOW some of you will say why would you push a change so small but i am just trying to learn GIT so then when i work on huge projects i am ready.
I basically want to commit the changes to the masters . How do i do this? I USUALLY see other peoples gits and they have messages like "fixed feature 1" 1 hour ago etc. So i want to do the same.
Please advice.
You would do that just like you pushed your earlier code - by pushing the commits you have made to remote repository.
If you are on the master branch, this will do: git push origin master (replace origin with your remote name - git remote -v will tell you all your remote names).
If you are on a feature branch, you can checkout to the master branch and then merge your feature branch - git checkout master and then git merge <feature branch>, and then push your changes again using git push origin master.
EDIT:
You can add a shortname using git remote add origin <link to remote repository>, and then use origin to push.
I am new to git as well and the answer above sounds better then mine. I have bash script on github (https://github.com/caroldomokos/columbo) which is work in progress for some time. I have the master locally as you do. When I make a change on the script I first do "git commit -a" and then "git push". I am in the "columbo" forlder on my pc. If you add a new file you first have to tell git to add it: "git add ". You can always use "git status" to see what is tracked and what has changed.To examplify I created this small sequence for you :-)
hpbcadom#LUBUNTU32:~/columbo$ echo "Git example" > example_file
hpbcadom#LUBUNTU32:~/columbo$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
example_file
nothing added to commit but untracked files present (use "git add" to track)
hpbcadom#LUBUNTU32:~/columbo$ git commit -a
[master d799b3a] to help I hope
1 file changed, 1 insertion(+)
create mode 100644 example_file
hpbcadom#LUBUNTU32:~/columbo$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Username for 'xxxs://github.com': caroldomokos
Password for 'xxxs://caroldomokos#github.com':
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To xxxs://github.com/caroldomokos/columbo
dadf5af..d799b3a master -> master
I hope it helps :-)

Git Working tree is dirty

If I execute git review git shows me "Working tree is dirty" error.
I made a commit and I sent to review. After that I update the branch from the upstream using git pull. Now I need to modify the previous commit message, so, there are my commands:
1) git reset <id-of-the-commit-to-modify>
2) git commit --amend
vim was opened to modify my commit. But here appears information about my commit and others commits as well and I don't know why. However, I modified the commit message and write/close vim.
3) git review
This command raise this error:
Errors running git rebase -i remotes/gerrit/master
doc/source/configuration.rst: needs update
doc/source/developing.rst: needs update
tools/sample_data.sh: needs update
Working tree is dirty
What I doing wrong?
git reset <id-of-the-commit-to-modify> without a mode option is defaulted to --mixed . This is what is said on the reset in the manual
--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
This basically means your index has been reset, but not your working files. So all files that you pulled from upstream are still left in your working tree.
You should use git reset --hard <id-of-the-commit-to-modify> This will reset your index and remove the files that came with your upstream pull. You can then amend your commit and send it for review.
once a change was pushed to Gerrit, then it can be fetched directly. On the Gerrit review board you can find the chekcout command for each patchset, something like this: git fetch ssh://ebalbar#gerrit.ericsson.se:29418/TCC/TitanSim refs/changes/86/129686/5 && git checkout FETCH_HEAD Then, you can amend the commit as usual, and push the new change again. AFter that checkout your local branch and reset it with the remote branch: git reset --hard origin/<remote_branch> also a nice answer how to modify a commit which was pushed directly.

How to switch repositories from one to the next

I was using a github repository from a previous developer.
I am the only coder on this project, so I forked the project over to my own github repository.
Now I would like to commit soley to my repo.
Unfortunately, I realized that I never changed my .git/config , so I was still committing to the old repo. I just changed it to the appropriate url, and when I type :
$> git status
It returns :
=> Working directory clean.
But I know its not because I have several commits I've made. So my local box has different code then what it is pointed to on my repository.
My question is this. Obviously I'm halfway through the process of doing this. Do I need to re-fork to update, and then I'm good. Or is there a special command I need to run to let my local box know its 'git status' command is targeting a new repo to compare itself to? Equally, am I missing something else very important :D ?
Thank you everyone.
You can use git remote to manage your remote
rename origin
git remote rename origin old_origin
add a new origin
git remote add origin git://github.com/my/forked/repo.git
git fetch origin # will create all the remote branches references
# in your local repo
You can also easily setup a new upstream for your current master branch (git 1.7 and more):
git branch --set-upstream master origin/master
The "nothing to commit (working directory clean)" message of git status won't prevent you to push.
After changing the origin, you should see:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by xxx commits.
#
nothing to commit (working directory clean)
That means you have some commits to push to your new origin.
Note: "git remote"(man) rename failed to rename a remote without fetch refspec, which has been corrected with Git 2.39 (Q4 2022).
See commit 5a97b38 (22 Sep 2022) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 20a5dd6, 10 Oct 2022)
remote: handle rename of remote without fetch refspec
Reported-by: John A. Leuenhagen
Signed-off-by: Jeff King
We return an error when trying to rename a remote that has no fetch refspec:
$ git config --unset-all remote.origin.fetch
$ git remote rename origin foo
fatal: could not unset 'remote.foo.fetch'
To make things even more confusing, we actually do complete the config modification, via git_config_rename_section().
After that we try to rewrite the fetch refspec (to say refs/remotes/foo instead of origin).
But our call to git_config_set_multivar() to remove the existing entries fails, since there aren't any, and it calls die().
We could fix this by using the "gently" form of the config call, and checking the error code.
But there is an even simpler fix: if we know that there are no refspecs to rewrite, then we can skip that part entirely.
git status only shows you the status of your working directory, not the entire repository. It seems like you only need to change the remotes that git push and git pull use by default. Open up .git/config and find your branch.<branch> entries and change them, as well as your remote.<remote> entries. For example, your master entry may look like this:
[branch "master"]
remote = origin
merge = refs/heads/master
Just change remote to reference your (forked) remote.
Also, your remote entry may look like the following:
[remote "myremote"]
url = git://github.com/me/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
You can add a push entry so that your master branch is pushed by default:
[remote "myremote"]
url = git://github.com/me/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
push = master
In whole, but I should include it in this answer. Is that before hand I manually altered my .git/config to include my new repository url. That's why I didn't have to rename or add any origin as Von suggested.
Then I just guessed this and performed
$> git fetch origin
Which returned
From git#github.com:gotoAndBliss/hq_channel
17326ca..043d395 master -> origin/master
* [new branch] panda_streaming -> origin/panda_streaming
+ 6ec9bf8...becbcc6 testing -> origin/testing (forced update)
Then on git status I got
# On branch testing
# Your branch is ahead of 'origin/testing' by 9 commits.
I git pushed origin testing, and I think I'm on target now.

Resources