Creating a Commit
Background
In code development, developers usually clone code from CodeArts Repo to the local PC to develop code locally, and the commit the code to CodeArts Repo after completing the phased development task. This section describes how to use the Git client to commit the modified code.
Prerequisites
Procedure
Generally, developers do not directly develop code in the master branch. Instead, they create a feature branch based on the master or develop branch, and develop code in it. Then they commit the feature branch to CodeArts Repo, and merge it into the master or develop branch. The preceding operations are simulated as follows:
- Go to the local repository directory and open the Git client. Take Git Bash as an example. The principles and commands of other Git management tools are the same.
- Create a feature1001 branch based on the master branch, switch to the created branch, and run the following command in the master branch:
git checkout -b feature1001 #Shown in 1 in the following figure.
This command creates a branch and then switches to the branch.
If the command is successfully executed, 2 in the following figure is shown. You can run the ls command to view the files of the branch (as shown in 3 in the following figure), which are the same as those of the master branch currently.
- Modify code in the feature branch (code development).
Git supports Linux commands. In this case, the touch command is used to create a file named newFeature1001.html, indicating that the developer has developed new features locally and a new file is added into the local code repository.
touch newFeature1001.html
Run the ls command again to view the created file.
- Run the add and commit commands to add the file from the working directory to the staging area, and then commit the file to the local repository. (For details, see Overview.)
You can also run the status command to check the file status.
- Run the status command. The command output shows that a file in the working directory is not included in version management, as shown in 1 in the following figure.
- Run the add command to add the file to the staging area, as shown in 2 in the following figure.
git add . # Period (.) means all files, including hidden files. You can also specify a file.
- Run the status command. The command output shows that the file has been added to the staging area and is waiting to be committed, as shown in 3 in the following figure.
- Run the commit command to commit the file to the local repository, as shown in 4 in the following figure.
git commit -m "<your_commit_message>"
- Check the file status again. If no file to be committed exists, the commit is successful, as shown in 5 in the following figure.
- Push a local branch to CodeArts Repo.
git push --set-upstream origin feature1001
Run the preceding command to create a branch that is the same as your local feature1001 branch in CodeArts Repo, and associate them and synchronize the branch.
origin indicates the alias of your CodeArts Repo. The default alias of a directly controllable repository is origin. You can also use the repository address.
If the push fails, check the connectivity.
- Check whether your network can access CodeArts Repo.
Run the following command on the Git client to test the network connectivity:
1
ssh -vT git@********.com
If the command output contains connect to host ********.com port 22: Connection timed out, your network is restricted from accessing CodeArts Repo. Contact your network administrator.
- Check whether the SSH Keys, HTTPS password is correctly configured. If necessary, regenerate a key and configure it on the CodeArts Repo console.
- Check the IP address whitelist. If no whitelist is configured, all IP addresses are allowed to access the repository. If a whitelist is configured, only IP addresses in the whitelist are allowed to access the repository.
- Check whether your network can access CodeArts Repo.
- View the CodeArts Repo repository branch.
Log in to CodeArts Repo and go to your repository. In the Files tab page, you can switch to your branch in CodeArts Repo.
If the branch you just committed is not displayed, your origin may be bound to another repository. Use the repository address to commit the branch again.
- Create a merge request. For details, see Managing MRs. Notify the approver to review the request and merge the new feature into the master or develop branch.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot