How to get `git-p4 sync` to work? - git-p4

I've successfully created a git branch called 'scaffold' by using git-p4.py clone.
I now want to sync the latest Perforce changes into the git branch so I'm trying git-p4.py sync --branch=scaffold but all that happens is the output of the following:
Syncing with origin first, using "git fetch origin"
Creating/updating branch(es) in refs/remotes/p4/ based on origin branch(es)
Performing incremental import into scaffold git branch
Depot paths: //depot/depot/path/to/code/
No changes to import!
After that, git status says nothing to commit (working directory clean).
How do I get this to work?

The following worked for me on my desktop but fails with fast-import failed on Jenkins:
git checkout scaffold
git p4 sync --branch=scaffold //depot/path/to/code/...#all
git push ssh://git#example.com:7999/repository/project.git +remotes/p4/scaffold:scaffold

Related

fatal: Could not resolve HEAD to a revision

I am trying to fetch my react-app
run this:
git fetch origin
then run this:
git rebase origin/main
but got an error
$ git rebase origin/main
fatal: Could not resolve HEAD to a revision
Try first a git status, to understand where you are in your local repository.
For instance, if you have just created an empty repository, and added origin, you could not rebase your current non-existent local branch on top of origin/main.
Check the output of git branch -avv.
If you have a branch main, try and switch back to it.
git switch main
Then, and only then, try a simple git pull.

Problems when it comes to committing changes to git after running 'npm run deploy' on my react app

So I have successfully deployed my react project on GitHub pages, there are a lot of useful guides on how to do this. However I am having issues when it comes to updating the project (it is harder to find good guides on this)
So lets say I make a change to my project on the code as it exists in folders on my computer.
Then I will run 'npm run deploy'. After doing this, I can see my changes have been successfully implemented on my online deployed site, so all good.
Then I run the following code to push the changes into the repository:
git add .
git commit -m "update"
That works fine, but I get an error at the next step:
git push -u origin master
When I do this I always get the same error message in the terminal:
error: failed to push some refs to 'https://github.com/redacted/redacted.github.io.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Can anyone please explain what is happening here, and what this error message means.
In the error message, does 'remote' mean the code as it exists in the GitHub repo, and 'local' mean the code on my computer? Why does the remote code and local code diverge after running 'npm run deploy'? In future, what is the best way for me to update the repository so that I don't keep running into this problem.
If it's important, here are my scripts on the package.json file:
"predeploy": "npm run build",
"deploy": "gh-pages -b master -d build",
hint: Updates were rejected because the remote contains work that you do
not [...] have locally.
There are commits on the remote that you don't have locally. To see them, you can use git diff. First, update the local representation of remote references in your repo:
git fetch
Now that you have an up-to-date local representation of what's on origin/master, you can see the differences with:
git diff origin/master
Git diff is one of the most important parts of the git tooling, so become acquainted with its syntax. This should show you what changes you've missed. you can also pull up the log of origin/master which will show the commit messages, authors, and dates with:
git log origin/master
If this loads up in an editor you don't recognize and the lower left of the screen is a : colon character, type q to quit. This program is called less.
All that helps you introspect the remote changes that you haven't incorporated locally. When you're ready to pull them into your own branch, simply issue:
git pull
This will apply missing commits to your local branch. If the local commits change the same lines as the remote commits, you'll end up with a git conflict. In this case you'll have to look at the conflicts and decide how to combine the two changes. Often, remote changes can be incorporated without causing any conflicts, but of course it depends on what's been changed on both sides.
A final note. What you absolutely do not want to do is git push -f. This will force push your changes to master, replacing its current history - in other words, you'll destroy the remote changes. Never do this. There's a time and a place for it, and once you get more comfortable with git diff and its behavior as a distributed change control system, you can revisit that advice.

Git trying to push non existent repository

I installed a new react app in Visual Studio Code and tried to push it to my git repository from local.
After "git add -A", "git commit -m "Initial commit" and "git push --set-upstream origin master" I get an error that it can't be pushed.
fatal: 'https//github.com/UserName/SomeOldProject' does not appear to
be a git repository
This "SomeOldProject" doesn't exist for a while now because I deleted it a few months ago from local and my git repo. I don't know where this comes from. I already deleted "create-react-app" and re-installed it but nothing changed.
I also had the problem that some old and deleted repositories showed up on local after I installed "create-react-app". Still don't know where this comes from, because I deleted most of them a long time ago.
Is there anything I can do here to clear some cache or something else so it won't track all the old files?
Are you sure is a remote configured in this repository?
Try this command:
git remote -v
This command should list your configured repositories, and check if exists a repository configured or if it's right.
If you need to add a new repository to your project, try this command:
git remote add origin <git_url>
This command add a new git repository using orgin (default name) as alias.
Look this tutorial to understand more about remotes: https://www.atlassian.com/git/tutorials/syncing

I try to deploy my Yeoman AngularJS static site to Github pages but the git subtree command always gets rejected

I am trying to deploy my AngularJS static site (which I began with Yeoman) as a Github page and was following the steps provided in the Yeoman deployment guide. I succeed in steps 1 and 2 but when I arrive at step 3, things go bad. Step 3 tells me to run
git subtree push --prefix dist origin gh-pages
When I run this is what I see
$ git subtree push --prefix dist origin gh-pages
git push using: origin gh-pages
To git#github.com:siddhion/maxmythic_angular.git
! [rejected] 5db3233d7c0822eedc5500409ce6a2d4b73ad427 -> gh-pages (non-fast-forward)
error: failed to push some refs to 'git#github.com:siddhion/maxmythic_angular.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I then I follow the hint and try
$ git pull origin master
From github.com:siddhion/maxmythic_angular
* branch master -> FETCH_HEAD
Already up-to-date.
and then tried git subtree push --prefix dist origin gh-pages again but got the same error as before.
At the Yeoman deployment page I see under the Some common errors section
You might get an error like this Updates were rejected because the tip
of your current branch is behind. You can solve this by force pushing
to the remote (be careful though, it will destroy whatever is already
there).
I am apprehensive to force the subtree push because I am new to git in general and not sure what is going to be destroyed. I mean, I currently do not have a gh-pages branch at my maxmythic_angular origin remote so I am not worried about that but I have my master, gh-pages-old and gh-pages-v1 branches there. Will they be destroyed if I run git subtree push --prefix dist origin gh-pages?
UPDATE
I went ahead and copied my work to another folder to be safe and I added --force to my git subtree push command and ran it. This is what I got
$ git subtree push --prefix dist origin gh-pages --force
error: unknown option `force'
usage: git subtree add --prefix=<prefix> <commit>
or: git subtree add --prefix=<prefix> <repository> <commit>
or: git subtree merge --prefix=<prefix> <commit>
or: git subtree pull --prefix=<prefix> <repository> <refspec...>
or: git subtree push --prefix=<prefix> <repository> <refspec...>
or: git subtree split --prefix=<prefix> <commit...>
-h, --help show the help
-q quiet
-d show debug messages
-P, --prefix ... the name of the subdir to split out
-m, --message ... use the given message as the commit message for the merge commit
options for 'split'
--annotate ... add a prefix to commit message of new commits
-b, --branch ... create a new branch from the split subtree
--ignore-joins ignore prior --rejoin commits
--onto ... try connecting new tree to an existing one
--rejoin merge the new branch back into HEAD
options for 'add', 'merge', 'pull' and 'push'
--squash merge subtree changes as a single commit
How can I get the git subtree push --prefix dist origin gh-pages command to work so I can deploy my site to gh-pages?
UPDATE
I wanted to see if this issue was to do with the instructions or just something fishy with my repo so I set up a new Angular app with yo angular and followed the deployment instructions. git subtree push worked this time. I still have no idea what happened to the gh-pages repo of mine. I will have to really learn git in and out.
I had the same problem. The problem was that I had dist already committed in the current repo. No as a subtree. The following steps should resolve the issue
// remove the dist and commit
rd /s dist
git commit -am "remove dist folder"
// add the subtree and push
git subtree add --prefix dist origin gh-pages
git subtree push --prefix dist origin gh-pages
That seemed to do the trick for me
I also used the subtree method for a while to push the typical Yeoman dist folder to a remote (in my case gh-pages). It's a make do but causes headaches when something gets changed on the server.
You then have to resort to much less elegant solutions which you describe above. And those create even more hassle, as you noticed.I believe for this particular workflow, using the subtree method is hack.
There's a much better solution to this: grunt-build-control by Rob Wierzbowski. Takes 10 mins to install but works like a charm and the whole deploying of the build folder to remotes becomes automatic. Completely version controlled and painless.
Its now also mentioned in the Yeoman wiki.

Hook to create/add a database dump file to repository on git pull

My aim is to minimize the steps needed to locally clone my website + database.
I have a central git repository on a webserver and a local clone. When I pull updates on my local machine, not only should I get the latest file versions from the remote repository but also should a script run on this webserver to dump the live database and additionally add it to the repository prior to delivering the pull.
My guess is that I need the following actions to happen on the remote machine when I fire git pull on the local machine prior to delivering the repository:
Create database dump file, e.g. dump.sql (by exectuting mysqldump)
Add dump.sql to repository
Commit dump.sql to repository
… and only then deliver the pull to the local machine.
What kind of git hook should I use for this?
I'd also appreciate any additional experience with such a scenario.
git help hooks lists the types of hooks and how they work, but there isn't a hook that you can use to do what you want (you'd need something like pre-upload that would be executed by git-upload-pack).
However, you could create a wrapper script around git-upload-pack on the server that performs the necessary actions and then executes the real git-upload-pack command:
find the git-upload-pack executable
rename it to git-upload-pack.real
create a new script called git-upload-pack somewhere in PATH that does the following:
use the arguments to find the Git repository
cd into the Git repository
if hooks/pre-upload exists and is an executable file:
run it
if the hook exited with a non-zero status:
print an error message to standard error
exit with a non-zero return value
run git-upload-pack.real with the original command-line arguments
create a hooks/pre-upload script in your Git repository that does whatever you want

Resources