Using ac2git followed by bitbucket - python

I am using ac2git to convert my accurev depot to git repository. I am able to successfully make the conversion however when I follow the steps after creating the new repository I am unable to push the changes representing the accurev transactions that are now commits.
What I mean is I loose the history, I am only able to see the hist and the diff files when I check the commit options on bitbucket.
I followed the following steps:
python ac2git.py
cd existing-project
git add --all
git commit -m "Initial Commit"
git remote add origin http://****#bitbucket.******.git
git push -u origin master
I am new to bitbucket so I am not sure what the problem is? Has anyone tried this accurev->git->bitbucket before?
In other words, how do I move my git repository on my local created as a result of ac2git to a new repository on bitbucket ?

Your first step is to create a repository in BitBucket. Then you simply need to follow BitBucket's instructions:
cd /path/to/my/repo
git remote add origin http://****#bitbucket.******.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push origin --tags # pushes up any tags

I'm not 100% certain that this is what has happened but it is worth noting that the ac2git script stores a lot of metadata under refs/ac2git/* refs, including a refs that will store a hist.xml, streams.xml and diff.xml in their commit history for each of your stream's transactions. See how_it_works.md which explains about refs/ac2git/depots/<depot_number>/streams/<stream_number>/info.
Though this ref acts as a branch, it shouldn't have been pushed up by invoking git push origin -u -all since the documentation claims that this only pushes things under refs/heads/. However, in case of errors the script may not correctly checkout a branch that was converted and it may leave your local repository in a detached HEAD state where it will have actually checked out one of the internal refs.
I don't know what a git push origin -u --all would do in this case for a brand new Bitbucket repo but if it had pushed your HEAD ref up to the repo then you would get this metadata on the remote.
However, for now this is just a theory and hopefully someone will be able to use this information to piece together a more clear solution for you.

Related

error: failed to push some refs to when pushing with a certain command

I keep getting this error when I do git push -u origin master
. git push works but that doesn't It's stuck with heroku too. When I do git push heroku master I get this same error message. All the answers on Stack Overflow say that it's because I didn't commit first but I did commit. I don't know what's wrong. If I don't solve this, I won't be able to follow along with my book and I'm tired of using the heroku GUI to push everything.
First thing: never use git push only until and unless you are 100% sure of which branch you are pushing to.
GitHub has a concept of default remote branch. so when you do git push you are actually pushing the code to the default branch.
You can check the default branch for your GitHub repository as below:
Now coming to your doubt
If the branch you are currently in on local is different (other than the one you want to push to remotely) lets say main, then if you do git push origin main while being on the master branch, Git will try to push your local master branch to the remote master branch, and if local master branch is behind the remote master branch in terms of commit or if their is any discrepancies (maybe someone forced push something or did a rebase), then you will get the issue error: failed to push some refs to when pushing with a certain command
So there are two resolutions to it:
recommended: Change to the branch you want to push to remote repository, pull the changes from remote, resolve the conflicts if any, do the rebase and then push it to the remote
If you are 100% sure that your code from local is correct and you want to replace the remote branch completely with your local branch you can do a force push as git push origin <BRANCH_NAME> -f. But this is too dangerous, at times it can lead to code loss especially in big projects where multiple developers are working on the same repo

Git Pycharm change only the local master branch to be exactly like origin master branch

I have 2 local branches: "master" and "fix".
I also have an origin remote repo with a master branch that is different from my local master branch.
the "fix" branch used to be a copy of the master branch, but then I made a lot of changes:
I changed some of the files, renamed others, added new ones and deleted some.
now, I want my local master branch to be the same as the remote master branch - without changing the "fix" branch!
when I use git pull it does not pull all of the files from the remote repository. I am not sure why.
when I use git reset --hard origin/master, it does make the local master the same as the remote one - which is what I wanted - but it also adds files to the "fix" branch!
why does this heepens?
how can I do this without the "fix" branch changing?
You need to commit your changes to the fix branch before switching to the master branch
#current branch: fix
git add .
git status # to verify that every thing is ready to be committed
git commit -m "your commit message"
git checkout master
# current branch: master
git status # to verify if you have commits that weren't yet pushed
git pull # add --rebase option if you have some commits not yet pushed to avoid adding merge commit
I hope it helps :)

How to update personal cloned github?

I recently downloaded an open-source project from github into my server using
$ git clone www.github.com/project_url
Then I added comments and descriptions inside the multiple files here and there.
When I went to the github repository of the original project github page,
many of the files were updated. But I'm hesitating to clone again because I think it would just overwrite every local files to which I wrote many of the comments.
Is there anyway I can download up-to-date files in the github,
but leave the comments that I added not being removed at the same time?
There are multiple strategies to go around this problem. A strategy is already explained. Another could be
Commit your changes (git commit -am <message>)
Do a git pull (git pull -r)
Resolve conflicts if any
Also, you can keep your changes separate in a separate branch. Here is what else can be done:
Create a separate branch in your local repository (git checkout -b <branch-name>, eg. git checkout -b new-branch)
commit changes in that new branch (git commit -am <message>)
Either you can merge now from your new branch to the old branch
git checkout old-branch; git merge new-branch.
resolve conflicts if any
OR
Raise a Pull Request after resolving any conflicts if any
You can use git stash for this. This will store everything you changed locally. Then you pull the changes from the original repository and then with 'git stash pop' your local changes will come back.
git stash
git pull
git stash pop
Conflicts can come up and need to be resolved.

How to use a pull request in my local copy of a Git branch?

I'm not familiar with Git, I only know how to download a master or dev branch of a python software project from Github and install into my system (I do not really use Git locally).
Now there is a "pull request" by a GitHub user which contains a feature I find useful but not in the main or dev branch. How can I use that in my local copy?
And if I manage to include it into my local copy, would it be lost if I later updated to the latest maaster/dev branch?
see: Git fetch remote branch
git fetch
git checkout <the name of the remote branch>
You can revert to any commit anytime you want, those changes are kept in the repository so you can visit different versions of it during the development on all branches. You need to do a merge command, which if, there's not any conflict with the patch contained in the pull request, will combine the code of the patch with the code of the repository. If there's conflicting code, like shared files for example, you will have to do the proper refactors and select which changes get inside or not.
Here you have basic information about merging different branches:
http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
Updating will only do a merge with the changes and your master. If you break something you can stash the changes and get to the original state.
Also I would suggest to checkout a fresh branch and apply that feature on the freshly created branch. If every thing works fine merge it to your master otherwise delete and forget it :P
if you dont know the branch name
use git fetch first to know the branch name
and then git checkout
Also maybe you can find this link useful

crontab automated git pull

I have a server deployed. I am writing a crontab task. It uses a python script that need to check if there is new push into the repository. If it finds a new push, it will pull and update the server code and should restart the server.
My problem is how to make the python script know if there is new commit into the repository?
I know you can use
git rev-list deployment..origin/deployment
to check if there is any commit is available on the remote server.
But how to implement in the python script and make it decide to know that it need to pull?
Thanks
Nick
You will need to contact the server in any case, so you might as well pull.
If you are on the current branch when you pull, and want to detect whether the current branch has changed, you can always do (note: written in shell)
BEFORE=$(git rev-parse HEAD)
# git pull here
AFTER=$(git rev-parse HEAD)
# Changes if $BEFORE is different from $AFTER
fge is correct. You cannot see if someone else pushed without first either doing a git pull origin or a git fetch origin. Your command would have worked with a git fetch origin first.
git fetch origin
git rev-list deployment..origin/deployment

Categories

Resources